Exemple #1
0
        [Test]         // Item (Int32)
        public void Indexer1_Level_Negative()
        {
            ContextStack stack = new ContextStack();

            stack.Push(new Foo());

            try {
                object context = stack [-1];
                Assert.Fail("#A1:" + context);
            } catch (ArgumentOutOfRangeException ex) {
                Assert.AreEqual(typeof(ArgumentOutOfRangeException), ex.GetType(), "#A2");
                Assert.IsNull(ex.InnerException, "#A3");
                Assert.AreEqual(new ArgumentOutOfRangeException("level").Message, ex.Message, "#A4");
                Assert.AreEqual("level", ex.ParamName, "#A5");
            }

            try {
                object context = stack [-5];
                Assert.Fail("#B1:" + context);
            } catch (ArgumentOutOfRangeException ex) {
                Assert.AreEqual(typeof(ArgumentOutOfRangeException), ex.GetType(), "#B2");
                Assert.IsNull(ex.InnerException, "#B3");
                Assert.AreEqual(new ArgumentOutOfRangeException("level").Message, ex.Message, "#B4");
                Assert.AreEqual("level", ex.ParamName, "#B5");
            }
        }
Exemple #2
0
        public static IRList analyse(List <AST_Node> program, SymbolTable globalScope)
        {
            Analyser.program = program;
            instructions     = new IRList();
            contextStack     = new ContextStack(16);
            enclosureStack   = new EnclosureStack(16);

            contextStack.Push(new Context(int.MaxValue, Context.Kind.STATEMENT));     // Just put something on the stack
            enclosureStack.Push(new Enclosure(NT.GLOBAL, null, globalScope, int.MaxValue));

            program.forEach((n, i) => Console.WriteLine("{0}: {1}".fill(i, n)));
            Console.WriteLine();

            for (cursor = 0; cursor < program.Count; incrementCursor(ref cursor))
            {
                Action <AST_Node> action;
                AST_Node          node = program[cursor];
                if (typeDefinitionAnalysers.TryGetValue(node.nodeType, out action))
                {
                    action(node);
                }
            }

            isDefineFase = false;

            for (cursor = 0; cursor < program.Count; incrementCursor(ref cursor))
            {
                analyseNode(program[cursor]);
            }

            return(instructions);
        }
 public void PushContext(Context ctx)
 {
     ContextStack.Push(CurrentContext);
     CurrentContext = ctx;
     NotifyMessage("コンテキストを変更しました。");
     ShowCommandsAsUsers();
 }
Exemple #4
0
        static void Main(string[] args)
        {
            //<Snippet2>
            // Create a ContextStack.
            ContextStack stack = new ContextStack();

            //</Snippet2>

            //<Snippet3>
            // Push ten items on to the stack and output the value of each.
            for (int number = 0; number < 10; number++)
            {
                Console.WriteLine("Value pushed to stack: " + number.ToString());
                stack.Push(number);
            }
            //</Snippet3>

            //<Snippet4>
            // Pop each item off the stack.
            object item = null;

            while ((item = stack.Pop()) != null)
            {
                Console.WriteLine("Value popped from stack: " + item.ToString());
            }
            //</Snippet4>
        }
        public override object Execute(List <string> args)
        {
            if (args.Count != 1 || !CacheContext.TryGetTag(args[0], out var tag))
            {
                return(false);
            }

            var oldContext = ContextStack.Context;

            TagInstance = tag;

            using (var stream = CacheContext.OpenTagCacheRead())
                TagDefinition = CacheContext.Deserialize(stream, TagInstance);

            ContextStack.Push(EditTagContextFactory.Create(ContextStack, CacheContext, TagInstance, TagDefinition));

            var groupName = CacheContext.GetString(TagInstance.Group.Name);
            var tagName   = TagInstance?.Name ?? $"0x{TagInstance.Index:X4}";

            Console.WriteLine($"Tag {tagName}.{groupName} has been opened for editing.");
            Console.WriteLine("New commands are now available. Enter \"help\" to view them.");
            Console.WriteLine("Use \"exit\" to return to {0}.", oldContext.Name);

            return(true);
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="AttachedContext" />
 ///     class.
 /// </summary>
 /// <param name="contextStack">The context stack.</param>
 /// <param name="context">The context.</param>
 /// <exception cref="System.ArgumentNullException">contextStack</exception>
 /// <autogeneratedoc />
 /// TODO Edit XML Comment Template for #ctor
 public AttachedContext(ContextStack <InfoContext> contextStack, InfoContext context)
 {
     _contextStack =
         contextStack ?? throw new ArgumentNullException(nameof(contextStack));
     _infoContext = context;
     contextStack.Push(_infoContext);
 }
Exemple #7
0
        [Test]         // Item (Int32)
        public void Indexer1()
        {
            ContextStack stack = new ContextStack();
            string       one   = "one";
            string       two   = "two";

            stack.Push(one);
            stack.Push(two);

            Assert.AreSame(two, stack [0], "#1");
            Assert.AreSame(one, stack [1], "#2");
            Assert.IsNull(stack [2], "#3");
            Assert.AreSame(two, stack.Pop(), "#4");
            Assert.AreSame(one, stack [0], "#5");
            Assert.IsNull(stack [1], "#6");
            Assert.AreSame(one, stack.Pop(), "#7");
            Assert.IsNull(stack [0], "#8");
            Assert.IsNull(stack [1], "#9");
        }
Exemple #8
0
        // methods and properties

        /// <summary>
        /// Enters a context.
        /// </summary>
        /// <include file='..\doc\include\Utilities/WorkContext.xml' path='WorkContext/Enter/Method/*' />
        /// <include file='..\doc\include\Utilities/WorkContext.xml' path='WorkContext/Enter/Signature_Text/*' />
        void Enter(string text)
        {
            _text    = text;
            _entered = true;
            if (EnableTracing)
            {
                Trace.WriteLine("Enter Context: " + text);
                Trace.Indent();
            }
            Stack.Push(this);
        }
 public IResultWriter BeginContext(string context, Globals.ResultWriterDestination dest)
 {
     //if (CurrentContext != null && CurrentContext.ContextsWritten++ > 0)
     //IncreaseIndent();
     if (CurrentContext != null)
     {
         ContextStack.Push(CurrentContext);
     }
     CurrentContext = new ResultContext(context);
     Write(context, dest);
     return(this);
 }
 public IResultWriter BeginContext(string context, Globals.ResultWriterDestination dest)
 {
     //if (CurrentContext != null && CurrentContext.ContextsWritten++ > 0)
     //IncreaseIndent();
     if (CurrentContext != null)
     {
         ContextStack.Push(CurrentContext);
     }
     CurrentContext = new ResultContext(context);
     Write(string.Concat(Enumerable.Repeat(Delimiter, IndentationLevel)) + context, dest);
     return(this.IncreaseIndent());
 }
Exemple #11
0
        private bool ParseStatement(TemplateStream stream, TokenList tokens, ContextStack context, ScopeStack scope)
        {
            if (scope.Current == Scope.Statement)
            {
                scope.Pop();
            }
            else if (scope.Current == Scope.Block)
            {
                var previous = stream.Peek(-1);
                if (previous == '$' || char.IsLetterOrDigit(previous))
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            var name       = stream.PeekWord();
            var identifier = context.Current.GetIdentifier(name);

            if (identifier != null)
            {
                tokens.Add(new Token(stream.Position, name.Length, stream.Line, TokenType.Identifier, context.Current, identifier.QuickInfo));
                stream.Advance(name.Length);

                if (identifier.Type == IdentifierType.Indexed)
                {
                    if (stream.Current == '(')
                    {
                        scope.Push(Scope.Filter);
                    }
                    if (stream.Current == '[')
                    {
                        scope.Push(Scope.Template);
                        context.Push(name, stream.Position);
                    }
                }
                else if (identifier.Type == IdentifierType.Boolean)
                {
                    if (stream.Current == '[')
                    {
                        scope.Push(Scope.True);
                    }
                }

                return(true);
            }

            return(false);
        }
Exemple #12
0
        [Fact] // Item (Int32)
        public void Indexer1_Level_Negative()
        {
            ContextStack stack = new ContextStack();

            stack.Push(new Foo());
            ArgumentOutOfRangeException ex;

            ex = Assert.Throws <ArgumentOutOfRangeException>(() => stack[-1]);
            Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType());
            Assert.Null(ex.InnerException);
            Assert.Equal(new ArgumentOutOfRangeException("level").Message, ex.Message);
            Assert.Equal("level", ex.ParamName);

            ex = Assert.Throws <ArgumentOutOfRangeException>(() => stack[-5]);
            Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType());
            Assert.Null(ex.InnerException);
            Assert.Equal(new ArgumentOutOfRangeException("level").Message, ex.Message);
            Assert.Equal("level", ex.ParamName);
        }
Exemple #13
0
 public IResultWriter BeginContext(string context, Globals.ResultWriterDestination dest)
 {
     if (CurrentContext != null)
     {
         if (CurrentContext.ContextsWritten++ > 0)
         {
             stdOut.Write("," + Environment.NewLine);
         }
         ContextStack.Push(CurrentContext);
         CurrentContext = new ResultContext(context);
     }
     else
     {
         CurrentContext = new ResultContext(context, 1);
     }
     Write(context.DoubleQuote() + ": {", dest);
     VerboseOut.WriteLine("Beginning context " + CurrentContext.Name);
     return(this);
 }
Exemple #14
0
        public override object Execute(List <string> args)
        {
            if (args.Count < 1)
            {
                return(false);
            }

            while (args.Count > 1)
            {
                switch (args[0].ToLower())
                {
                case "memory":
                    break;

                default:
                    throw new FormatException(args[0]);
                }

                args.RemoveAt(0);
            }

            var fileName = new FileInfo(args[0]);

            if (!fileName.Exists)
            {
                Console.WriteLine($"Cache {fileName.FullName} does not exist");
                return(true);
            }

            Console.Write("Loading cache...");

            GameCache blamCache = GameCache.Open(fileName);

            ContextStack.Push(PortingContextFactory.Create(ContextStack, Cache, blamCache));

            Console.WriteLine("done.");

            return(true);
        }