PageRenderTime 27ms CodeModel.GetById 12ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/IronPython_Main/Languages/Ruby/Ruby/Runtime/Globals/GlobalVariables.cs

#
C# | 118 lines | 81 code | 13 blank | 24 comment | 0 complexity | dab070eabc9289f577554a7215a0d6f1 MD5 | raw file
  1/* ****************************************************************************
  2 *
  3 * Copyright (c) Microsoft Corporation. 
  4 *
  5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
  6 * copy of the license can be found in the License.html file at the root of this distribution. If 
  7 * you cannot locate the  Apache License, Version 2.0, please send an email to 
  8 * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
  9 * by the terms of the Apache License, Version 2.0.
 10 *
 11 * You must not remove this notice, or any other, from this software.
 12 *
 13 *
 14 * ***************************************************************************/
 15
 16using IronRuby.Compiler;
 17
 18namespace IronRuby.Runtime {
 19    internal enum GlobalVariableId {
 20        MatchData,
 21        EntireMatch,
 22        MatchLastGroup,
 23        PreMatch,
 24        PostMatch,
 25
 26        CurrentException,
 27        CurrentExceptionBacktrace,
 28        ItemSeparator,
 29        StringSeparator,
 30        InputSeparator,
 31        OutputSeparator,
 32        LastInputLine,
 33        InputFileName,
 34        CommandLineProgramPath,
 35        CommandLineArguments,
 36        LoadPath,
 37        LoadedFiles,
 38        InputContent,
 39        OutputStream,
 40        LastInputLineNumber,
 41
 42        InputStream,
 43        ErrorOutputStream,
 44        SafeLevel,
 45        Verbose,
 46        KCode,
 47        ChildProcessExitStatus
 48    }
 49
 50    public static class GlobalVariables {
 51        // regex:
 52        public static readonly GlobalVariable MatchData = new SpecialGlobalVariableInfo(GlobalVariableId.MatchData);
 53        public static readonly GlobalVariable EntireMatch = new SpecialGlobalVariableInfo(GlobalVariableId.EntireMatch);
 54        public static readonly GlobalVariable MatchLastGroup = new SpecialGlobalVariableInfo(GlobalVariableId.MatchLastGroup);
 55        public static readonly GlobalVariable PreMatch = new SpecialGlobalVariableInfo(GlobalVariableId.PreMatch);
 56        public static readonly GlobalVariable PostMatch = new SpecialGlobalVariableInfo(GlobalVariableId.PostMatch);
 57
 58        public static readonly GlobalVariable CurrentException = new SpecialGlobalVariableInfo(GlobalVariableId.CurrentException);
 59        public static readonly GlobalVariable CurrentExceptionBacktrace = new SpecialGlobalVariableInfo(GlobalVariableId.CurrentExceptionBacktrace);
 60
 61        public static readonly GlobalVariable CommandLineArguments = new SpecialGlobalVariableInfo(GlobalVariableId.CommandLineArguments);
 62        public static readonly GlobalVariable LastInputLine = new SpecialGlobalVariableInfo(GlobalVariableId.LastInputLine);
 63        public static readonly GlobalVariable InputFileName = new SpecialGlobalVariableInfo(GlobalVariableId.InputFileName);
 64        public static readonly GlobalVariable CommandLineProgramPath = new SpecialGlobalVariableInfo(GlobalVariableId.CommandLineProgramPath);
 65        public static readonly GlobalVariable InputContent = new SpecialGlobalVariableInfo(GlobalVariableId.InputContent);
 66        public static readonly GlobalVariable LastInputLineNumber = new SpecialGlobalVariableInfo(GlobalVariableId.LastInputLineNumber);
 67
 68        public static readonly GlobalVariable InputSeparator = new SpecialGlobalVariableInfo(GlobalVariableId.InputSeparator);
 69        public static readonly GlobalVariable ItemSeparator = new SpecialGlobalVariableInfo(GlobalVariableId.ItemSeparator);
 70        public static readonly GlobalVariable StringSeparator = new SpecialGlobalVariableInfo(GlobalVariableId.StringSeparator);
 71        public static readonly GlobalVariable OutputSeparator = new SpecialGlobalVariableInfo(GlobalVariableId.OutputSeparator);
 72
 73        public static readonly GlobalVariable LoadPath = new SpecialGlobalVariableInfo(GlobalVariableId.LoadPath);
 74        public static readonly GlobalVariable LoadedFiles = new SpecialGlobalVariableInfo(GlobalVariableId.LoadedFiles);
 75
 76        public static readonly GlobalVariable OutputStream = new SpecialGlobalVariableInfo(GlobalVariableId.OutputStream);
 77        public static readonly GlobalVariable InputStream = new SpecialGlobalVariableInfo(GlobalVariableId.InputStream);
 78        public static readonly GlobalVariable ErrorOutputStream = new SpecialGlobalVariableInfo(GlobalVariableId.ErrorOutputStream);
 79
 80        public static readonly GlobalVariable SafeLevel = new SpecialGlobalVariableInfo(GlobalVariableId.SafeLevel);
 81        public static readonly GlobalVariable Verbose = new SpecialGlobalVariableInfo(GlobalVariableId.Verbose);
 82        public static readonly GlobalVariable KCode = new SpecialGlobalVariableInfo(GlobalVariableId.KCode);
 83        public static readonly GlobalVariable ChildProcessExitStatus = new SpecialGlobalVariableInfo(GlobalVariableId.ChildProcessExitStatus);
 84
 85        //
 86        // Defines variables backed by a field on RubyContext or Scope and variables that derived from them.
 87        // Also variables that need type check on assignment are defined here.
 88        //
 89        // Other variables are simply looked up in the dictionary on RubyContext. All uses of such variables in libraries 
 90        // go thru alias table so they don't need a direct reference from RubyContext.
 91        //
 92        internal static void DefineVariablesNoLock(RubyContext/*!*/ context) {
 93            // scope based variables (regex and input line):
 94            context.DefineGlobalVariableNoLock(Symbols.MatchData, MatchData);
 95            context.DefineGlobalVariableNoLock(Symbols.EntireMatch, EntireMatch);
 96            context.DefineGlobalVariableNoLock(Symbols.MatchLastGroup, MatchLastGroup);
 97            context.DefineGlobalVariableNoLock(Symbols.PreMatch, PreMatch);
 98            context.DefineGlobalVariableNoLock(Symbols.PostMatch, PostMatch);
 99            context.DefineGlobalVariableNoLock(Symbols.LastInputLine, LastInputLine);
100
101            // directly accessed variables provided by execution context:
102            context.DefineGlobalVariableNoLock(Symbols.CommandLineProgramPath, CommandLineProgramPath);
103            context.DefineGlobalVariableNoLock(Symbols.CurrentException, CurrentException);
104            context.DefineGlobalVariableNoLock(Symbols.CurrentExceptionBacktrace, CurrentExceptionBacktrace);
105            context.DefineGlobalVariableNoLock(Symbols.CommandLineArguments, CommandLineArguments);
106            context.DefineGlobalVariableNoLock(Symbols.InputSeparator, InputSeparator);
107            context.DefineGlobalVariableNoLock(Symbols.ItemSeparator, ItemSeparator);
108            context.DefineGlobalVariableNoLock(Symbols.StringSeparator, StringSeparator);
109            context.DefineGlobalVariableNoLock(Symbols.OutputSeparator, OutputSeparator);
110            context.DefineGlobalVariableNoLock(Symbols.InputContent, InputContent);
111            context.DefineGlobalVariableNoLock(Symbols.OutputStream, OutputStream);
112            context.DefineGlobalVariableNoLock(Symbols.LoadedFiles, LoadedFiles);
113            context.DefineGlobalVariableNoLock(Symbols.LoadPath, LoadPath);
114            context.DefineGlobalVariableNoLock(Symbols.LastInputLineNumber, LastInputLineNumber);
115            context.DefineGlobalVariableNoLock(Symbols.ChildProcessExitStatus, ChildProcessExitStatus);
116        }    
117    }       
118}