예제 #1
0
파일: Preprocessor.cs 프로젝트: wyrover/ccm
        public void ConsumeIfDef(LookAheadLangParser parser)
        {
            Debug.Assert(Preprocessor.NextIsIfdef(parser));

            while (!(parser.PeekNextKeyword().Equals("if") ||
                     parser.PeekNextKeyword().Equals("ifdef") ||
                     parser.PeekNextKeyword().Equals("def")))
            {
                ConumseNextKeyWordSpaceOutput();
            }

            ConumseNextKeyWordSpaceOutput();
        }
예제 #2
0
파일: Preprocessor.cs 프로젝트: wyrover/ccm
        public StreamReader Process()
        {
            try
            {
                Stack <bool> blockInclusion = new Stack <bool>();

                blockInclusion.Push(true); // start by including next block of text

                do
                {
                    if (Preprocessor.NextIsIfdef(this.parser))
                    {
                        ConsumeIfDef(this.parser);

                        // if we are currently excluding a block, i.e nested #if's, just push 0 onto the inclusion
                        if (!blockInclusion.Peek())
                        {
                            blockInclusion.Push(false);
                        }
                        else
                        {
                            blockInclusion.Push(EvaluateExpression());
                        }

                        MoveToNextLineSpaceOutput();
                    }
                    else if (Preprocessor.NextIsElse(this.parser) && blockInclusion.Count > 1)
                    {
                        // just reverse the inclusion book-keeping

                        bool blockShouldInclude = blockInclusion.Pop();

                        // check if parent inclusing says no
                        if (!blockInclusion.Peek())
                        {
                            blockInclusion.Push(false);
                        }
                        else
                        {
                            blockInclusion.Push(!blockShouldInclude);
                        }

                        MoveToNextLineSpaceOutput();
                    }
                    else if (Preprocessor.NextIsEndif(this.parser) && blockInclusion.Count > 1)
                    {
                        blockInclusion.Pop();
                        MoveToNextLineSpaceOutput();
                    }
                    else if (Preprocessor.NextIsIfndef(this.parser))
                    {
                        ConsumeIfndef(this.parser);

                        if (!blockInclusion.Peek())
                        {
                            blockInclusion.Push(false);
                        }
                        else
                        {
                            blockInclusion.Push(!EvaluateExpression());
                        }

                        MoveToNextLineSpaceOutput();
                    }
                    else if (Preprocessor.NextIsCommentBlock(this.parser))
                    {
                        ConsumeComments();
                    }
                    else if (this.parser.PeekNextKeyword().Equals("#"))
                    {
                        ConsumeDirectiveMultiLine();
                    }
                    else
                    {
                        if (blockInclusion.Peek())
                        {
                            this.sb.Append(this.parser.NextKeyword());
                        }
                        else
                        {
                            ConumseNextKeyWordSpaceOutput(); // move the stream ahead without including its data...
                        }
                    }
                }while (true);
            }
            catch (EndOfStreamException)
            {
            }
            catch (Exception)
            {
                throw new PreprocessorException();
            }

            return(Preprocessor.GetTextStream(this.sb.ToString()));
        }