コード例 #1
0
ファイル: SrcMLCppParser.cs プロジェクト: abb-iss/Sando
        public List <ProgramElement> Parse(string fileName)
        {
            var      programElements = new List <ProgramElement>();
            XElement sourceElements;

            if (SrcMLService != null)
            {
                sourceElements = SrcMLService.GetXElementForSourceFile(fileName);
                if (sourceElements != null)
                {
                    programElements = Parse(fileName, sourceElements);
                }
                else
                {
                    FileLogger.DefaultLogger.ErrorFormat("SrcMLCppParser: File not found in SrcMLService: {0}", fileName);
                }
            }
            else if (Archive != null)
            {
                sourceElements = Archive.GetXElementForSourceFile(fileName);
                if (sourceElements != null)
                {
                    programElements = Parse(fileName, sourceElements);
                }
                else
                {
                    LogEvents.ParserFileNotFoundInArchiveError(this, fileName);
                }
            }
            else if (Generator != null)
            {
                string outFile = Path.GetTempFileName();
                try {
                    //This is a C++ parser, so we'll convert the input file as C++ no matter what the file extension is
                    Generator.GenerateSrcMLFromFile(fileName, outFile, Language.CPlusPlus);
                    sourceElements = SrcMLElement.Load(outFile);
                    if (sourceElements != null)
                    {
                        programElements = Parse(fileName, sourceElements);
                    }
                } finally {
                    File.Delete(outFile);
                }
            }
            else
            {
                throw new InvalidOperationException("SrcMLCppParser - Archive and Generator are both null");
            }

            return(programElements);
        }