Пример #1
0
        /// <summary>
        /// Construct a SourceFile from the given arguments
        /// </summary>
        /// <param name="Location">Location of the file</param>
        /// <param name="Text">Contents of the file</param>
        /// <param name="Flags">Properties of the file</param>
        public SourceFile(FileReference Location, TextBuffer Text, SourceFileFlags Flags)
        {
            this.Location = Location;
            this.Text     = Text;
            this.Flags    = Flags;

            // Read the preprocsesor markup
            if (Text == null)
            {
                Markup = new PreprocessorMarkup[0];
            }
            else
            {
                Markup = PreprocessorMarkup.ParseArray(Text);
            }

            // Find the markup range which excludes header guards
            BodyMinIdx = 0;
            BodyMaxIdx = Markup.Length;
            while (BodyMaxIdx > BodyMinIdx)
            {
                if (!SkipPragmaOnce(Markup, ref BodyMinIdx) && !SkipHeaderGuard(Markup, ref BodyMinIdx, ref BodyMaxIdx))
                {
                    break;
                }
            }

            // Inline files must not have a header guard (because it would result in a different derivation), and must not include any other files (because we include them
            // from their original location)
            if ((Flags & SourceFileFlags.Inline) != 0)
            {
                if (HasHeaderGuard)
                {
                    throw new Exception("Files marked as 'inline' may not have a header guard, since they will be included directly.");
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Construct a SourceFile from the given arguments
        /// </summary>
        /// <param name="Location">Location of the file</param>
        /// <param name="Text">Contents of the file</param>
        /// <param name="Flags">Properties of the file</param>
        public SourceFile(FileReference Location, TextBuffer Text, SourceFileFlags Flags)
        {
            // Check for directives specifying additional flags for this file in the source text
            if (Text != null)
            {
                foreach (string Line in Text.Lines)
                {
                    Match Match = OptionsPattern.Match(Line);
                    if (Match.Success)
                    {
                        foreach (string FlagText in Match.Groups[1].Value.Split(',').Select(x => x.Trim()).Where(x => x.Length > 0))
                        {
                            SourceFileFlags Flag;
                            if (Enum.TryParse(FlagText, true, out Flag))
                            {
                                Flags |= Flag;
                            }
                            else
                            {
                                throw new Exception(String.Format("{0}: Invalid source file flag '{1}'", Location, FlagText));
                            }
                        }
                    }
                }
            }

            // Inline files cannot be standalone
            if ((Flags & SourceFileFlags.Inline) != 0)
            {
                Flags &= ~SourceFileFlags.Standalone;
            }

            // Save the parameters
            this.Location = Location;
            this.Text     = Text;
            this.Flags    = Flags;

            // Read the preprocsesor markup
            if (Text == null)
            {
                Markup = new PreprocessorMarkup[0];
            }
            else
            {
                Markup = PreprocessorMarkup.ParseArray(Text);
            }

            // Find the markup range which excludes header guards
            BodyMinIdx = 0;
            BodyMaxIdx = Markup.Length;
            while (BodyMaxIdx > BodyMinIdx)
            {
                if (!SkipPragmaOnce(Markup, ref BodyMinIdx) && !SkipHeaderGuard(Markup, ref BodyMinIdx, ref BodyMaxIdx))
                {
                    break;
                }
            }

            // Inline files must not have a header guard (because it would result in a different derivation), and must not include any other files (because we include them
            // from their original location)
            if ((Flags & SourceFileFlags.Inline) != 0)
            {
                if (HasHeaderGuard)
                {
                    throw new Exception("Files marked as 'inline' may not have a header guard, since they will be included directly.");
                }
            }
        }