1
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
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:
9
// The above copyright notice and this permission notice shall be included in all copies or
10
// substantial portions of the Software.
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.
20
using System.Collections.Generic;
21
using ICSharpCode.NRefactory.TypeSystem.Implementation;
23
namespace ICSharpCode.NRefactory.CSharp
26
/// C# compiler settings.
29
public class CompilerSettings : AbstractFreezable
31
protected override void FreezeInternal()
33
conditionalSymbols = FreezableHelper.FreezeList(conditionalSymbols);
34
specificWarningsAsErrors = FreezableHelper.FreezeList(specificWarningsAsErrors);
35
disabledWarnings = FreezableHelper.FreezeList(disabledWarnings);
36
base.FreezeInternal();
40
/// Creates a new CompilerSettings instance.
42
public CompilerSettings()
46
bool allowUnsafeBlocks = true;
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.
52
public bool AllowUnsafeBlocks {
53
get { return allowUnsafeBlocks; }
55
FreezableHelper.ThrowIfFrozen(this);
56
allowUnsafeBlocks = value;
60
bool checkForOverflow;
63
/// Gets/Sets whether overflow checking is enabled.
64
/// The default is <c>false</c>. This setting effects semantic analysis.
66
public bool CheckForOverflow {
67
get { return checkForOverflow; }
68
set { checkForOverflow = value; }
71
Version languageVersion = new Version((int)Mono.CSharp.LanguageVersion.Default, 0);
74
/// Gets/Sets the language version used by the parser.
75
/// Using language constructs newer than the supplied version will result in parser errors.
77
public Version LanguageVersion {
78
get { return languageVersion; }
80
FreezableHelper.ThrowIfFrozen(this);
82
throw new ArgumentNullException();
83
languageVersion = value;
87
IList<string> conditionalSymbols = new List<string>();
90
/// Gets/Sets the list of conditional symbols that are defined project-wide.
92
public IList<string> ConditionalSymbols {
93
get { return conditionalSymbols; }
96
bool treatWarningsAsErrors;
98
public bool TreatWarningsAsErrors {
99
get { return treatWarningsAsErrors; }
101
FreezableHelper.ThrowIfFrozen(this);
102
treatWarningsAsErrors = value;
106
IList<int> specificWarningsAsErrors = new List<int>();
109
/// Allows treating specific warnings as errors without setting <see cref="TreatWarningsAsErrors"/> to true.
111
public IList<int> SpecificWarningsAsErrors {
112
get { return specificWarningsAsErrors; }
115
int warningLevel = 4;
117
public int WarningLevel {
118
get { return warningLevel; }
120
FreezableHelper.ThrowIfFrozen(this);
121
warningLevel = value;
125
IList<int> disabledWarnings = new List<int>();
128
/// Disables the specified warnings.
130
public IList<int> DisabledWarnings {
131
get { return disabledWarnings; }
134
internal Mono.CSharp.CompilerSettings ToMono()
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);