Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveProjectManagement/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory.CSharp-5.5.0/Parser/CompilerSettings.cs @ 15377

Last change on this file since 15377 was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 4.6 KB
Line 
1// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4// software and associated documentation files (the "Software"), to deal in the Software
5// without restriction, including without limitation the rights to use, copy, modify, merge,
6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7// to whom the Software is furnished to do so, subject to the following conditions:
8//
9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11//
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19using System;
20using System.Collections.Generic;
21using ICSharpCode.NRefactory.TypeSystem.Implementation;
22
23namespace ICSharpCode.NRefactory.CSharp
24{
25  /// <summary>
26  /// C# compiler settings.
27  /// </summary>
28  [Serializable]
29  public class CompilerSettings : AbstractFreezable
30  {
31    protected override void FreezeInternal()
32    {
33      conditionalSymbols = FreezableHelper.FreezeList(conditionalSymbols);
34      specificWarningsAsErrors = FreezableHelper.FreezeList(specificWarningsAsErrors);
35      disabledWarnings = FreezableHelper.FreezeList(disabledWarnings);
36      base.FreezeInternal();
37    }
38   
39    /// <summary>
40    /// Creates a new CompilerSettings instance.
41    /// </summary>
42    public CompilerSettings()
43    {
44    }
45   
46    bool allowUnsafeBlocks = true;
47   
48    /// <summary>
49    /// Gets/Sets whether <c>unsafe</c> code is allowed.
50    /// The default is <c>true</c>. If set to false, parsing unsafe code will result in parser errors.
51    /// </summary>
52    public bool AllowUnsafeBlocks {
53      get { return allowUnsafeBlocks; }
54      set {
55        FreezableHelper.ThrowIfFrozen(this);
56        allowUnsafeBlocks = value;
57      }
58    }
59   
60    bool checkForOverflow;
61   
62    /// <summary>
63    /// Gets/Sets whether overflow checking is enabled.
64    /// The default is <c>false</c>. This setting effects semantic analysis.
65    /// </summary>
66    public bool CheckForOverflow {
67      get { return checkForOverflow; }
68      set { checkForOverflow = value; }
69    }
70   
71    Version languageVersion = new Version((int)Mono.CSharp.LanguageVersion.Default, 0);
72   
73    /// <summary>
74    /// Gets/Sets the language version used by the parser.
75    /// Using language constructs newer than the supplied version will result in parser errors.
76    /// </summary>
77    public Version LanguageVersion {
78      get { return languageVersion; }
79      set {
80        FreezableHelper.ThrowIfFrozen(this);
81        if (value == null)
82          throw new ArgumentNullException();
83        languageVersion = value;
84      }
85    }
86   
87    IList<string> conditionalSymbols = new List<string>();
88   
89    /// <summary>
90    /// Gets/Sets the list of conditional symbols that are defined project-wide.
91    /// </summary>
92    public IList<string> ConditionalSymbols {
93      get { return conditionalSymbols; }
94    }
95   
96    bool treatWarningsAsErrors;
97   
98    public bool TreatWarningsAsErrors {
99      get { return treatWarningsAsErrors; }
100      set {
101        FreezableHelper.ThrowIfFrozen(this);
102        treatWarningsAsErrors = value;
103      }
104    }
105   
106    IList<int> specificWarningsAsErrors = new List<int>();
107   
108    /// <summary>
109    /// Allows treating specific warnings as errors without setting <see cref="TreatWarningsAsErrors"/> to true.
110    /// </summary>
111    public IList<int> SpecificWarningsAsErrors {
112      get { return specificWarningsAsErrors; }
113    }
114   
115    int warningLevel = 4;
116   
117    public int WarningLevel {
118      get { return warningLevel; }
119      set {
120        FreezableHelper.ThrowIfFrozen(this);
121        warningLevel = value;
122      }
123    }
124   
125    IList<int> disabledWarnings = new List<int>();
126   
127    /// <summary>
128    /// Disables the specified warnings.
129    /// </summary>
130    public IList<int> DisabledWarnings {
131      get { return disabledWarnings; }
132    }
133   
134    internal Mono.CSharp.CompilerSettings ToMono()
135    {
136      var s = new Mono.CSharp.CompilerSettings();
137      s.Unsafe = allowUnsafeBlocks;
138      s.Checked = checkForOverflow;
139      s.Version = (Mono.CSharp.LanguageVersion)languageVersion.Major;
140      s.WarningsAreErrors = treatWarningsAsErrors;
141      s.WarningLevel = warningLevel;
142      foreach (int code in disabledWarnings)
143        s.SetIgnoreWarning(code);
144      foreach (int code in specificWarningsAsErrors)
145        s.AddWarningAsError(code);
146      foreach (string sym in conditionalSymbols)
147        s.AddConditionalSymbol(sym);
148      return s;
149    }
150  }
151}
Note: See TracBrowser for help on using the repository browser.