Пример #1
0
        /// <summary>
        /// Gets and converts preprocessor directive.
        /// </summary>
        /// <param name="preprocessorSymbol">The preprocessor symbol.</param>
        /// <param name="parent">The parent code part.</param>
        /// <param name="generated">Indicates whether the preprocessor directive lies within a block of generated code.</param>
        /// <returns>Returns the preprocessor directive.</returns>
        private Preprocessor GetPreprocessorDirectiveToken(Symbol preprocessorSymbol, Reference<ICodePart> parent, bool generated)
        {
            Param.AssertNotNull(preprocessorSymbol, "preprocessorSymbol");
            Param.AssertNotNull(parent, "parent");
            Param.Ignore(generated);

            Debug.Assert(preprocessorSymbol != null && preprocessorSymbol.SymbolType == SymbolType.PreprocessorDirective, "Expected a preprocessor directive");

            // Get the type of the preprocessor directive.
            int bodyIndex;
            string type = CsParser.GetPreprocessorDirectiveType(preprocessorSymbol, out bodyIndex);
            if (type == null)
            {
                throw new SyntaxException(this.document.SourceCode, preprocessorSymbol.LineNumber);
            }

            // Create the correct preprocessor object type.
            Preprocessor preprocessor = null;
            if (type == "region")
            {
                Region region = new Region(preprocessorSymbol.Text, preprocessorSymbol.Location, parent, true, generated);
                this.symbols.PushRegion(region);
                preprocessor = region;
            }
            else if (type == "endregion")
            {
                Region endregion = new Region(preprocessorSymbol.Text, preprocessorSymbol.Location, parent, false, generated);
                Region startregion = this.symbols.PopRegion();

                if (startregion == null)
                {
                    throw new SyntaxException(this.document.SourceCode, preprocessorSymbol.LineNumber);
                }

                startregion.Partner = endregion;
                endregion.Partner = startregion;

                preprocessor = endregion;
            }
            else if (type == "if")
            {
                preprocessor = this.GetConditionalCompilationDirective(
                    preprocessorSymbol, ConditionalCompilationDirectiveType.If, bodyIndex, parent, generated);
            }
            else if (type == "elif")
            {
                preprocessor = this.GetConditionalCompilationDirective(
                    preprocessorSymbol, ConditionalCompilationDirectiveType.Elif, bodyIndex, parent, generated);
            }
            else if (type == "else")
            {
                preprocessor = this.GetConditionalCompilationDirective(
                    preprocessorSymbol, ConditionalCompilationDirectiveType.Else, bodyIndex, parent, generated);
            }
            else if (type == "endif")
            {
                preprocessor = this.GetConditionalCompilationDirective(
                    preprocessorSymbol, ConditionalCompilationDirectiveType.Endif, bodyIndex, parent, generated);
            }
            else
            {
                preprocessor = new Preprocessor(preprocessorSymbol.Text, preprocessorSymbol.Location, parent, generated);
            }

            return preprocessor;
        }
Пример #2
0
        /// <summary>
        /// Pushes a region onto the region stack.
        /// </summary>
        /// <param name="region">The region to add.</param>
        public void PushRegion(Region region)
        {
            Param.AssertNotNull(region, "region");

            this.regions.Push(region);
            if (region.IsGeneratedCodeRegion)
            {
                this.IncrementGeneratedCodeBlocks();
            }
        }
Пример #3
0
        private Preprocessor GetPreprocessorDirectiveToken(Symbol preprocessorSymbol, bool generated)
        {
            int num;
            string preprocessorDirectiveType = CsParser.GetPreprocessorDirectiveType(preprocessorSymbol, out num);
            if (preprocessorDirectiveType == null)
            {
                throw new SyntaxException(this.document.SourceCode, preprocessorSymbol.LineNumber);
            }
            switch (preprocessorDirectiveType)
            {
                case "region":
                {
                    Region region = new Region(preprocessorSymbol.Text, preprocessorSymbol.Location, true, generated);
                    this.symbols.PushRegion(region);
                    return region;
                }
                case "endregion":
                {
                    Region region2 = new Region(preprocessorSymbol.Text, preprocessorSymbol.Location, false, generated);
                    Region region3 = this.symbols.PopRegion();
                    if (region3 == null)
                    {
                        throw new SyntaxException(this.document.SourceCode, preprocessorSymbol.LineNumber);
                    }
                    region3.Partner = region2;
                    region2.Partner = region3;
                    return region2;
                }
                case "if":
                    return this.GetConditionalCompilationDirective(preprocessorSymbol, ConditionalCompilationDirectiveType.If, num, generated);

                case "elif":
                    return this.GetConditionalCompilationDirective(preprocessorSymbol, ConditionalCompilationDirectiveType.Elif, num, generated);

                case "else":
                    return this.GetConditionalCompilationDirective(preprocessorSymbol, ConditionalCompilationDirectiveType.Else, num, generated);

                case "endif":
                    return this.GetConditionalCompilationDirective(preprocessorSymbol, ConditionalCompilationDirectiveType.Endif, num, generated);
            }
            return new Preprocessor(preprocessorSymbol.Text, preprocessorSymbol.Location, generated);
        }
Пример #4
0
 public void PushRegion(Region region)
 {
     this.regions.Push(region);
     if (region.IsGeneratedCodeRegion)
     {
         this.IncrementGeneratedCodeBlocks();
     }
 }