示例#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>
        /// Gets the flags for a new source file
        /// </summary>
        /// <param name="File">The workspace file being read</param>
        /// <returns>Flags for the corresponding source file</returns>
        public static SourceFileFlags GetSourceFileFlags(WorkspaceFile File)
        {
            string NormalizedPath = File.NormalizedPathFromBranchRoot;

            if (NormalizedPath == null || IsExternalHeaderPath(NormalizedPath))
            {
                return(SourceFileFlags.Pinned | SourceFileFlags.External);
            }

            SourceFileFlags Flags = SourceFileFlags.Standalone;

            if (NormalizedPath.EndsWith(".inl") || NormalizedPath.EndsWith(".inc") || NormalizedPath.EndsWith(".generated.h"))
            {
                Flags = (Flags | SourceFileFlags.Pinned) & ~SourceFileFlags.Standalone;
            }
            if (NormalizedPath.IndexOf("/public/") != -1 || NormalizedPath.IndexOf("/classes/") != -1)
            {
                Flags |= SourceFileFlags.Public;
            }
            if (NormalizedPath.IndexOf("/intermediate/") != -1)
            {
                if (NormalizedPath.EndsWith(".generated.h"))
                {
                    Flags |= SourceFileFlags.GeneratedHeader | SourceFileFlags.Inline | SourceFileFlags.Public;
                }
                else if (NormalizedPath.EndsWith("classes.h"))
                {
                    Flags |= SourceFileFlags.GeneratedClassesHeader | SourceFileFlags.Public;
                }
            }
            if (NormalizedPath.EndsWith(".cpp") || NormalizedPath.IndexOf("/windows/") != -1 || NormalizedPath.IndexOf("/linux/") != -1)
            {
                Flags |= SourceFileFlags.Pinned;
            }

            if (NormalizedPath.EndsWith("fwd.h") && !IgnoreFwdHeaders.Contains(NormalizedPath))
            {
                Flags |= SourceFileFlags.FwdHeader;
            }

            if (InlineFileNames.Contains(NormalizedPath))
            {
                Flags = (Flags | SourceFileFlags.Inline) & ~SourceFileFlags.Standalone;
            }
            if (PinnedFileNames.Contains(NormalizedPath))
            {
                Flags = (Flags | SourceFileFlags.Pinned) & ~SourceFileFlags.Standalone;
            }
            if (NotStandaloneFileNames.Contains(NormalizedPath))
            {
                Flags &= ~SourceFileFlags.Standalone;
            }
            if (AggregateFileNames.Contains(NormalizedPath))
            {
                Flags |= SourceFileFlags.Aggregate;
            }
            if (AllowMultipleFragmentFileNames.Contains(NormalizedPath))
            {
                Flags |= SourceFileFlags.AllowMultipleFragments;
            }
            if (ShouldIgnoreExports(NormalizedPath))
            {
                Flags |= SourceFileFlags.IgnoreExportedSymbols;
            }
            return(Flags);
        }
示例#3
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.");
                }
            }
        }