public CSharpParseOptions WithXSharpSpecificOptions(XSharpSpecificCompilationOptions opt)
        {
            var result = new CSharpParseOptions(this);

            result.SetXSharpSpecificOptions(opt);
            return(result);
        }
        public void SetXSharpSpecificOptions(XSharpSpecificCompilationOptions opt)
        {
            if (opt != null)
            {
                ArrayZero          = opt.ArrayZero;
                CaseSensitive      = opt.CaseSensitive;
                ClrVersion         = opt.ClrVersion;
                TargetDLL          = opt.TargetDLL;
                Dialect            = opt.Dialect;
                DefaultNamespace   = opt.NameSpace;
                DefaultIncludeDir  = opt.DefaultIncludeDir;
                ImplicitNamespace  = opt.ImplicitNameSpace;
                DumpAST            = opt.DumpAST;
                WindowsDir         = opt.WindowsDir;
                SystemDir          = opt.SystemDir;
                NoStdDef           = opt.NoStdDef;
                NoClipCall         = opt.NoClipCall;
                ShowDefs           = opt.ShowDefs;
                ShowIncludes       = opt.ShowIncludes;
                StdDefs            = opt.StdDefs;
                Verbose            = opt.Verbose;
                PreprocessorOutput = opt.PreProcessorOutput;
                ParseLevel         = opt.ParseLevel;
#if !VSPARSER
                IncludePaths = opt.IncludePaths.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToImmutableArray();
#else
                IncludePaths = opt.IncludePaths.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
#endif
                VoInitAxitMethods                   = opt.Vo1;
                VONullStrings                       = opt.Vo2;
                VirtualInstanceMethods              = opt.Vo3;
                VOSignedUnsignedConversion          = opt.Vo4;
                VOClipperCallingConvention          = opt.Vo5;
                VOResolveTypedFunctionPointersToPtr = opt.Vo6;
                VOImplicitCastsAndConversions       = opt.Vo7;
                VOPreprocessorBehaviour             = opt.Vo8;
                VOAllowMissingReturns               = opt.Vo9;
                VOCompatibleIIF                     = opt.Vo10;
                VOArithmeticConversions             = opt.Vo11;
                VOClipperIntegerDivisions           = opt.Vo12;
                VOStringComparisons                 = opt.Vo13;
                VOFloatConstants                    = opt.Vo14;
                VOUntypedAllowed                    = opt.Vo15;
                VOClipperConstructors               = opt.Vo16;
                XPPInheritFromAbstract              = opt.Xpp1;
                XPPUntypedmain                      = opt.Xpp2;
                FoxInheritUnknown                   = opt.Fox1;
                RuntimeAssemblies                   = opt.RuntimeAssemblies;
                Overflow            = opt.Overflow;
                ConsoleOutput       = opt.ConsoleOutput;
                ParseLevel          = opt.ParseLevel;
                AllowNamedArguments = opt.AllowNamedArguments;
                SaveAsCSharp        = opt.SaveAsCSharp;
                MemVars             = opt.MemVars;
                InitLocals          = opt.InitLocals;
                UndeclaredMemVars   = opt.UndeclaredMemVars;
                AllowUnsafe         = opt.AllowUnsafe;
            }
            LanguageVersion = LanguageVersion.CSharp7_3;
        }
        public void SetXSharpSpecificOptions(XSharpSpecificCompilationOptions opt)
        {
            if (opt != null)
            {
                ArrayZero = opt.ArrayZero;
                //VoInitAxitMethods = opt.Vo1;              // Handled in the parser
                VONullStrings              = opt.Vo2;
                VirtualInstanceMethods     = opt.Vo3;
                VOSignedUnsignedConversion = opt.Vo4;
                //VOClipperCallingConvention = opt.Vo5;     // Handled in the parser
                VOResolveTypedFunctionPointersToPtr = opt.Vo6;
                VOImplicitCastsAndConversions       = opt.Vo7;
                //VOPreprocessorBehaviour = opt.Vo8;        // Handled in the parser
                //VOAllowMissingReturns = opt.Vo9;          // Handled in the parser
                VOCompatibleIIF         = opt.Vo10;
                VOArithmeticConversions = opt.Vo11;
                //VOClipperIntegerDivisions = opt.Vo12;     // Handled in the parser
                VOStringComparisons = opt.Vo13;
                //VOFloatConstants = opt.Vo14;              // Handled in the parser
                //VOUntypedAllowed = opt.Vo15;              // Handled in the parser
                //VOClipperConstructors = opt.Vo16;         // Handled in the parser
                //XPPInheritFromAbstract = opt.Xpp1;        // Handled in the parser
                //XPPUntypedmain= opt.Xpp2;                 // Handled in the parser
                //FoxInheritUnknown= opt.Fox1;              // Handled in the parser

                Dialect           = opt.Dialect;
                ImplicitNameSpace = opt.ImplicitNameSpace;
                LateBinding       = opt.LateBinding;
                UndeclaredMemVars = opt.UndeclaredMemVars;
                MemVars           = opt.MemVars;
                TargetDLL         = opt.TargetDLL;
                RuntimeAssemblies = opt.RuntimeAssemblies;
                //InitLocals = opt.InitLocals;
                AllowUnsafe = opt.AllowUnsafe;
            }
        }
 internal CSharpCompilationOptions WithXSharpSpecificOptions(XSharpSpecificCompilationOptions opt)
 {
     SetXSharpSpecificOptions(opt);
     return(this);
 }
        internal bool ParseXSharpArgument(ref string name, ref string value, string arg, List <Diagnostic> diagnostics)
        {
            if (options == null)
            {
                options = new XSharpSpecificCompilationOptions();
            }

            bool   handled  = true;
            bool   positive = !name.EndsWith("-");
            bool   encode   = false;
            string oldname  = name;

            if (name.EndsWith("+") || name.EndsWith("-"))
            {
                name = name.Substring(0, name.Length - 1);
            }
            switch (name)
            {
            case "az":
                options.ArrayZero = positive;
                encode            = true;
                break;

            case "cf":
                OptionNotImplemented(diagnostics, oldname, "Compiling for Compact Framework");
                break;

            case "dialect":
                XSharpDialect dialect = XSharpDialect.Core;
                if (string.IsNullOrEmpty(value))
                {
                    AddDiagnostic(diagnostics, ErrorCode.ERR_SwitchNeedsString, MessageID.IDS_Text.Localize(), "/dialect:");
                }
                else if (!TryParseDialect(value, XSharpDialect.Core, out dialect))
                {
                    AddDiagnostic(diagnostics, ErrorCode.ERR_InvalidDialect, value);
                }
                options.Dialect = dialect;
                break;

            case "clr":     // CLR
                OptionNotImplemented(diagnostics, oldname, "Specify CLR version");
                encode = true;
                break;

            case "cs":
                options.CaseSensitive      = positive;
                XSharpString.CaseSensitive = positive;
                break;

            case "i":
                if (value == null)
                {
                    AddDiagnostic(diagnostics, ErrorCode.ERR_SwitchNeedsString, MessageID.IDS_Text.Localize(), "/i:");
                }
                else
                {
                    if (value.StartsWith("\"") && value.EndsWith("\""))
                    {
                        value = value.Substring(1, value.Length - 2);
                    }
                    options.IncludePaths = string.IsNullOrEmpty(options.IncludePaths) ? value : options.IncludePaths + ';' + value;
                }
                break;

            case "initlocals":
                options.InitLocals = positive;
                encode             = true;
                break;

            case "ins":
                options.ImplicitNameSpace = positive;
                encode = true;
                break;

            case "lb":
                options.LateBinding = positive;
                encode = true;
                break;

            case "namedarguments":
                options.AllowNamedArguments = positive;
                encode = true;
                break;

            case "noclipcall":
                options.NoClipCall = positive;
                break;

            case "norun":
                OptionNotImplemented(diagnostics, oldname, "NoRun compiler option. To achieve the same result in X# simply remove the references to the X# and/or Vulcan runtime DLLs.");
                break;

            case "nostddefs":
                options.NoStdDef = positive;
                break;

            case "ns":
                if (value == null)
                {
                    AddDiagnostic(diagnostics, ErrorCode.ERR_SwitchNeedsString, MessageID.IDS_Text.Localize(), "/ns:");
                }
                else
                {
                    options.NameSpace = value;
                }
                break;

            case "fovf":        // synonym for checked
            case "ovf":         // synonym for checked
                if (options.ExplicitOptions.HasFlag(CompilerOption.Overflow) && positive != options.Overflow)
                {
                    AddDiagnostic(diagnostics, ErrorCode.ERR_ConflictingCommandLineOptions, arg, options.PreviousArgument);
                }
                options.PreviousArgument = arg;
                encode = true;

                options.Overflow = positive;
                if (positive)
                {
                    name = "checked+";
                }
                else
                {
                    name = "checked-";
                }
                handled = false;
                break;

            case "languageversion":
                handled = true;
                break;

            case "lexonly":
                options.ParseLevel = ParseLevel.Lex;
                break;

            case "memvar":
                options.MemVars = positive;
                encode          = true;
                break;

            case "undeclared":
                options.UndeclaredMemVars = positive;
                encode = true;
                break;

            case "parseonly":
                options.ParseLevel = ParseLevel.Parse;
                break;

            case "out":
                if (!string.IsNullOrEmpty(value))
                {
                    value = value.Trim();
                    if (value.StartsWith("\"") && value.EndsWith("\""))
                    {
                        value = value.Substring(1, value.Length - 2);
                    }
                    string fn = System.IO.Path.GetFileName(value).ToLower();
                    switch (fn)
                    {
                    case "xsharp.core.dll":
                        options.TargetDLL = XSharpTargetDLL.Core;
                        break;

                    case "xsharp.data.dll":
                        options.TargetDLL = XSharpTargetDLL.Data;
                        break;

                    case "xsharp.rt.dll":
                        options.TargetDLL = XSharpTargetDLL.RT;
                        break;

                    case "xsharp.vo.dll":
                        options.TargetDLL = XSharpTargetDLL.VO;
                        break;

                    case "xsharp.rdd.dll":
                        options.TargetDLL = XSharpTargetDLL.RDD;
                        break;

                    case "xsharp.xpp.dll":
                        options.TargetDLL = XSharpTargetDLL.XPP;
                        break;

                    case "xsharp.vfp.dll":
                        options.TargetDLL = XSharpTargetDLL.VFP;
                        break;

                    case "vowin32apilibrary.dll":
                        options.TargetDLL = XSharpTargetDLL.VOWin32Api;
                        break;

                    case "vosystemclasses.dll":
                        options.TargetDLL = XSharpTargetDLL.VOSystemClasses;
                        break;

                    case "vorddclasses.dll":
                        options.TargetDLL = XSharpTargetDLL.VORDDClasses;
                        break;

                    case "vosqlclasses.dll":
                        options.TargetDLL = XSharpTargetDLL.VOSQLClasses;
                        break;

                    case "voguiclasses.dll":
                        options.TargetDLL = XSharpTargetDLL.VOGuiClasses;
                        break;

                    case "vointernetclasses.dll":
                        options.TargetDLL = XSharpTargetDLL.VOInternetClasses;
                        break;

                    case "voconsoleclasses.dll":
                        options.TargetDLL = XSharpTargetDLL.VOConsoleClasses;
                        break;

                    default:
                        options.TargetDLL = XSharpTargetDLL.Other;
                        break;
                    }
                }
                handled = false;
                break;

            case "ppo":
                options.PreProcessorOutput = positive;
                break;

            case "r":
            case "reference":
                if (!string.IsNullOrEmpty(value))
                {
                    // /r:"reference"
                    // /r:alias=reference
                    // /r:alias="reference"
                    // /r:reference;reference
                    // /r:"path;containing;semicolons"
                    // /r:"unterminated_quotes
                    // /r:"quotes"in"the"middle
                    // /r:alias=reference;reference      ... error 2034
                    // /r:nonidf=reference               ... error 1679
                    var pos = value.IndexOf('=');
                    if (pos >= 0 && value[pos] == '=')
                    {
                        value = value.Substring(pos + 1);
                    }
                    if (value.StartsWith("\"") && value.EndsWith("\""))
                    {
                        value = value.Substring(1, value.Length - 2);
                    }
                    string filename = value;
                    if (value.IndexOf(";") != -1)
                    {
                        foreach (var fname in  ParseSeparatedPaths(value).Where((path) => !string.IsNullOrWhiteSpace(path)))
                        {
                            SetOptionFromReference(fname);
                        }
                    }
                    else
                    {
                        SetOptionFromReference(filename);
                    }
                }
                handled = false;
                break;

            case "s":
                options.ParseLevel = ParseLevel.SyntaxCheck;
                break;

            case "showdefs":
            case "showdefines":
                options.ShowDefs = positive;
                break;

            case "showincludes":
                options.ShowIncludes = positive;
                break;

            case "stddefs":
                if (value == null)
                {
                    AddDiagnostic(diagnostics, ErrorCode.ERR_SwitchNeedsString, MessageID.IDS_Text.Localize(), "/stddefs:");
                }
                else
                {
                    if (value.StartsWith("\"") && value.EndsWith("\""))
                    {
                        value = value.Substring(1, value.Length - 2);
                    }
                    options.StdDefs = value;
                }
                break;


            case "tocs":
                options.SaveAsCSharp = positive;
                break;

            case "ast":
                options.DumpAST = positive;
                break;

            case "usenativeversion":
                options.UseNativeVersion = true;
                break;

            case "verbose":
                options.Verbose      = true;
                options.ShowIncludes = true;
                break;

            case "vo1":         // Init & Axit mapped to .ctor and .dtor
                options.Vo1 = positive;
                encode      = true;
                break;

            case "vo2":         // Initialize Strings to Empty string
                options.Vo2 = positive;
                encode      = true;
                break;

            case "vo3":         // All methods Virtual
                options.Vo3 = positive;
                encode      = true;
                break;

            case "vo4":         // Implicit signed/unsigned integer conversions
                options.Vo4 = positive;
                encode      = true;
                break;

            case "vo5":         // Implicit CLIPPER calling convention
                options.Vo5 = positive;
                encode      = true;
                break;

            case "vo6":         // Resolve typed function PTR to PTR
                options.Vo6 = positive;
                encode      = true;
                break;

            case "vo7":         // Compatible implicit cast & conversion
                options.Vo7 = positive;
                encode      = true;
                break;

            case "vo8":         // Compatible preprocessor
                options.Vo8 = positive;
                encode      = true;
                break;

            case "vo9":         // Allow missing RETURN
                options.Vo9 = positive;
                encode      = true;
                break;

            case "vo10":        // Compatible IIF
                options.Vo10 = positive;
                encode       = true;
                break;

            case "vo11":        // VO arithmetic conversions
                options.Vo11 = positive;
                encode       = true;
                break;

            case "vo12":        // Clipper integer divisions
                options.Vo12 = positive;
                encode       = true;
                break;

            case "vo13":        // VO String comparisons
                options.Vo13 = positive;
                encode       = true;
                break;

            case "vo14":        // VO FLoat Literals
                options.Vo14 = positive;
                encode       = true;
                break;

            case "vo15":        // VO Untyped allowed
                options.Vo15 = positive;
                encode       = true;
                break;

            case "vo16":        // VO Add Clipper CC Missing constructors
                options.Vo16 = positive;
                encode       = true;
                break;

            case "wx":           // disable warning
                name    = "warnaserror+";
                handled = false;
                break;

            case "xpp1":           // classes inherit from XPP.Abstract
                options.Xpp1 = positive;
                encode       = true;
                break;

            case "xpp2":           // untyped main instead of Start
                options.Xpp2 = positive;
                encode       = true;
                break;

            case "fox1":           // Classes inherit from unknown
                options.Fox1 = positive;
                encode       = true;
                break;

            case "unsafe":
                options.AllowUnsafe = positive;
                handled             = false; // there is also an 'unsafe' option in Roslyn
                name = oldname;
                break;

            default:
                name    = oldname;
                handled = false;
                break;
            }
            if (encode)
            {
                options.ExplicitOptions |= CompilerOptionDecoder.Decode(name);
            }
            return(handled);
        }
 internal void ResetXSharpCommandlineOptions()
 {
     options = new XSharpSpecificCompilationOptions();
 }