Exemplo n.º 1
0
        internal override void ValidateOptions(ArrayBuilder <Diagnostic> builder)
        {
            ValidateOptions(builder, MessageProvider.Instance);

            // Validate LanguageVersion not SpecifiedLanguageVersion, after Latest/Default has been converted:
            if (!LanguageVersion.IsValid())
            {
                builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_BadLanguageVersion, LanguageVersion.ToString()));
            }

            if (!PreprocessorSymbols.IsDefaultOrEmpty)
            {
                foreach (var symbol in PreprocessorSymbols)
                {
                    if (symbol == null)
                    {
                        builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_InvalidPreprocessingSymbol, "null"));
                    }
                    else if (!SyntaxFacts.IsValidIdentifier(symbol))
                    {
                        builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_InvalidPreprocessingSymbol, symbol));
                    }
                }
            }
        }
Exemplo n.º 2
0
        public CSharpParseOptions(
            LanguageVersion languageVersion     = LanguageVersion.CSharp6,
            DocumentationMode documentationMode = DocumentationMode.Parse,
            SourceCodeKind kind = SourceCodeKind.Regular,
            IEnumerable <string> preprocessorSymbols = null)
            : this(languageVersion, documentationMode, kind, preprocessorSymbols.ToImmutableArrayOrEmpty())
        {
            if (!languageVersion.IsValid())
            {
                throw new ArgumentOutOfRangeException(nameof(languageVersion));
            }

            if (!kind.IsValid())
            {
                throw new ArgumentOutOfRangeException(nameof(kind));
            }

            if (preprocessorSymbols != null)
            {
                foreach (var preprocessorSymbol in preprocessorSymbols)
                {
                    if (!SyntaxFacts.IsValidIdentifier(preprocessorSymbol))
                    {
                        throw new ArgumentException("preprocessorSymbols");
                    }
                }
            }
        }
Exemplo n.º 3
0
        public CSharpParseOptions(
            LanguageVersion languageVersion     = LanguageVersion.Default,
            DocumentationMode documentationMode = DocumentationMode.Parse,
            SourceCodeKind kind = SourceCodeKind.Regular,
            IEnumerable <string> preprocessorSymbols = null)
            : this(languageVersion,
                   documentationMode,
                   kind,
                   preprocessorSymbols.ToImmutableArrayOrEmpty(),
                   ImmutableDictionary <string, string> .Empty)
        {
            // We test the mapped value, LanguageVersion, rather than the parameter, languageVersion,
            // which has not had "Latest" mapped to the latest version yet.
            if (!LanguageVersion.IsValid())
            {
                throw new ArgumentOutOfRangeException(nameof(languageVersion));
            }

            if (!kind.IsValid())
            {
                throw new ArgumentOutOfRangeException(nameof(kind));
            }

            if (preprocessorSymbols != null)
            {
                foreach (var preprocessorSymbol in preprocessorSymbols)
                {
                    if (!SyntaxFacts.IsValidIdentifier(preprocessorSymbol))
                    {
                        throw new ArgumentException(nameof(preprocessorSymbol));
                    }
                }
            }
        }
Exemplo n.º 4
0
        public CSharpParseOptions(
            LanguageVersion languageVersion     = LanguageVersion.CSharp6,
            DocumentationMode documentationMode = DocumentationMode.Parse,
            SourceCodeKind kind = SourceCodeKind.Regular,
            ImmutableArray <string> preprocessorSymbols = default(ImmutableArray <string>))
            : this(languageVersion, documentationMode, kind, preprocessorSymbols.NullToEmpty(), privateCtor : true)
        {
            if (!languageVersion.IsValid())
            {
                throw new ArgumentOutOfRangeException("languageVersion");
            }

            if (!kind.IsValid())
            {
                throw new ArgumentOutOfRangeException("kind");
            }

            if (!preprocessorSymbols.IsDefaultOrEmpty)
            {
                foreach (var preprocessorSymbol in preprocessorSymbols)
                {
                    if (!SyntaxKindFacts.IsValidIdentifier(preprocessorSymbol))
                    {
                        throw new ArgumentException("preprocessorSymbols");
                    }
                }
            }
        }
Exemplo n.º 5
0
        //warnaserror[+|-]
        //warnaserror[+|-]:<warn list>
        //unsafe[+|-]
        //warn:<n>
        //nowarn:<warn list>

        public ParseOptions(
            CompatibilityMode compatibility          = CompatibilityMode.None,
            LanguageVersion languageVersion          = CSharp.LanguageVersion.CSharp4,
            IEnumerable <string> preprocessorSymbols = null,
            bool suppressDocumentationCommentParse   = false,
            SourceCodeKind kind = SourceCodeKind.Regular)
        {
            if (!compatibility.IsValid())
            {
                throw new ArgumentOutOfRangeException("compatibility");
            }
            if (!languageVersion.IsValid())
            {
                throw new ArgumentOutOfRangeException("languageVersion");
            }
            if (!kind.IsValid())
            {
                throw new ArgumentOutOfRangeException("kind");
            }

            this.Compatibility       = compatibility;
            this.LanguageVersion     = languageVersion;
            this.PreprocessorSymbols = preprocessorSymbols.AsReadOnlyOrEmpty();
            this.SuppressDocumentationCommentParse = suppressDocumentationCommentParse;
            this.Kind = kind;
        }
Exemplo n.º 6
0
 public override void ValidateOptions(ArrayBuilder <Diagnostic> builder)
 {
     base.ValidateOptions(builder);
     // Validate LanguageVersion not SpecifiedLanguageVersion, after Latest/Default has been converted:
     if (!LanguageVersion.IsValid())
     {
         builder.Add(MetaErrorCode.ERR_BadLanguageVersion.ToDiagnosticWithNoLocation(LanguageVersion.ToString()));
     }
 }
Exemplo n.º 7
0
        public SoalParseOptions WithLanguageVersion(LanguageVersion version)
        {
            if (version == this.LanguageVersion)
            {
                return(this);
            }

            if (!version.IsValid())
            {
                throw new ArgumentOutOfRangeException(nameof(version));
            }

            return(new SoalParseOptions(this)
            {
                LanguageVersion = version
            });
        }
Exemplo n.º 8
0
 public SoalParseOptions(
     LanguageVersion languageVersion     = LanguageVersion.Soal1,
     DocumentationMode documentationMode = DocumentationMode.Parse,
     SourceCodeKind kind = SourceCodeKind.Regular)
     : base(kind, documentationMode)
 {
     if (!languageVersion.IsValid())
     {
         throw new ArgumentOutOfRangeException(nameof(languageVersion));
     }
     if (!kind.IsValid())
     {
         throw new ArgumentOutOfRangeException(nameof(kind));
     }
     this.LanguageVersion = languageVersion;
     _features            = ImmutableDictionary <string, string> .Empty;
 }
Exemplo n.º 9
0
        /// <summary>
        /// Parse a LanguageVersion from a string input, as the command-line compiler does.
        /// </summary>
        public static bool TryParse(this string version, out LanguageVersion result)
        {
            if (version == null)
            {
                result = LanguageVersion.Default;
                return(true);
            }

            switch (version.ToLowerInvariant())
            {
            case "iso-1":
                result = LanguageVersion.CSharp1;
                return(true);

            case "iso-2":
                result = LanguageVersion.CSharp2;
                return(true);

            case "default":
                result = LanguageVersion.Default;
                return(true);

            case "latest":
                result = LanguageVersion.Latest;
                return(true);

            case "7.1":
                result = LanguageVersion.CSharp7_1;
                return(true);

            default:
                if (int.TryParse(version, NumberStyles.None, CultureInfo.InvariantCulture, out int versionNumber) && versionNumber <= 7)
                {
                    result = (LanguageVersion)versionNumber;
                    if (result.IsValid())
                    {
                        return(true);
                    }
                }

                result = LanguageVersion.Default;
                return(false);
            }
        }
Exemplo n.º 10
0
        public CSharpParseOptions WithLanguageVersion(LanguageVersion version)
        {
            version = version.MapLatestToVersion();

            if (version == this.LanguageVersion)
            {
                return(this);
            }

            if (!version.IsValid())
            {
                throw new ArgumentOutOfRangeException(nameof(version));
            }

            return(new CSharpParseOptions(this)
            {
                LanguageVersion = version
            });
        }
Exemplo n.º 11
0
        public CSharpParseOptions WithLanguageVersion(LanguageVersion version)
        {
            if (version == this.LanguageVersion)
            {
                return(this);
            }

            if (!version.IsValid())
            {
                throw new ArgumentOutOfRangeException("version");
            }

            return(new CSharpParseOptions(
                       version,
                       this.DocumentationMode,
                       this.Kind,
                       this.PreprocessorSymbols,
                       privateCtor: true
                       ));
        }
Exemplo n.º 12
0
        //warnaserror[+|-]
        //warnaserror[+|-]:<warn list>
        //unsafe[+|-]
        //warn:<n>
        //nowarn:<warn list>

        public ParseOptions(
            CompatibilityMode compatibility = CompatibilityMode.None,
            LanguageVersion languageVersion = CSharp.LanguageVersion.CSharp4,
            IEnumerable<string> preprocessorSymbols = null,
            bool suppressDocumentationCommentParse = false,
            SourceCodeKind kind = SourceCodeKind.Regular)
        {
            if (!compatibility.IsValid())
            {
                throw new ArgumentOutOfRangeException("compatibility");
            }
            if (!languageVersion.IsValid())
            {
                throw new ArgumentOutOfRangeException("languageVersion");
            }
            if (!kind.IsValid())
            {
                throw new ArgumentOutOfRangeException("kind");
            }

            this.Compatibility = compatibility;
            this.LanguageVersion = languageVersion;
            this.PreprocessorSymbols = preprocessorSymbols.AsReadOnlyOrEmpty();
            this.SuppressDocumentationCommentParse = suppressDocumentationCommentParse;
            this.Kind = kind;
        }