示例#1
0
        private ASTContext ParseInternal(string[] sourceFiles)
        {
            var parserOptions = new ParserOptions
            {
                Verbose         = true,
                ASTContext      = new CppSharp.Parser.AST.ASTContext(),
                LanguageVersion = LanguageVersion.GNUC
            };

            parserOptions.SetupIncludes();

            foreach (var includeDir in IncludeDirs)
            {
                parserOptions.AddIncludeDirs(includeDir);
            }

            foreach (var define in Defines)
            {
                parserOptions.AddDefines(define);
            }

            var project = new Project();

            foreach (var filePath in sourceFiles)
            {
                var sourceFile = project.AddFile(filePath);
                sourceFile.Options = parserOptions;
            }

            var clangParser = new ClangParser(new CppSharp.Parser.AST.ASTContext());

            clangParser.SourcesParsed += OnSourceFileParsed;
            clangParser.ParseProject(project, false);
            return(ClangParser.ConvertASTContext(clangParser.ASTContext));
        }
示例#2
0
        private ASTContext ParseInternal(string[] sourceFiles)
        {
            var parserOptions = new ParserOptions
            {
                Verbose         = true,
                ASTContext      = new CppSharp.Parser.AST.ASTContext(),
                LanguageVersion = LanguageVersion.C99_GNU
            };

            parserOptions.SetupMSVC(VisualStudioVersion.Latest);

            foreach (var includeDir in IncludeDirs)
            {
                parserOptions.AddIncludeDirs(includeDir);
            }

            foreach (var define in Defines)
            {
                parserOptions.AddDefines(define);
            }

            var clangParser = new ClangParser(new CppSharp.Parser.AST.ASTContext());

            clangParser.SourcesParsed += OnSourceFileParsed;
            clangParser.ParseSourceFiles(sourceFiles, parserOptions);
            return(ClangParser.ConvertASTContext(clangParser.ASTContext));
        }
示例#3
0
        public void ParseHeader(string file)
        {
            var parserProject = new Project();
            var parser        = new CppSharp.ClangParser();
            var sourceFile    = parserProject.AddFile(file);
            var options       = new ParserOptions();

            parser.SourcesParsed = OnParserResult;

            options.SetupMSVC(VisualStudioVersion.VS2012);

            foreach (var includeDirectory in includeDirectories.Values)
            {
                options.addSystemIncludeDirs(includeDirectory.FullName);
            }

            sourceFile.Options = options;

            try
            {
                parser.ParseProject(parserProject, false);
            }
            catch (Exception ex)
            {
                SetDiagnosticsStatus("Error parsing {0}, Error:{1}", file, ex.Message);
            }

            parser.ASTContext.Dispose();

            entities.SaveChanges();
        }
示例#4
0
        public bool ParseLibraries()
        {
            ClangParser.LibraryParsed += OnFileParsed;
            foreach (Module module in Options.Modules)
            {
                using var linkerOptions = new LinkerOptions(Context.LinkerOptions);
                foreach (string libraryDir in module.LibraryDirs)
                {
                    linkerOptions.AddLibraryDirs(libraryDir);
                }

                foreach (string library in module.Libraries)
                {
                    if (!Context.Symbols.Libraries.Any(( NativeLibrary l ) => l.FileName == library))
                    {
                        linkerOptions.AddLibraries(library);
                    }
                }

                using ParserResult parserResult = ClangParser.ParseLibrary(linkerOptions);
                if (parserResult.Kind == ParserResultKind.Success)
                {
                    for (uint num = 0u; num < parserResult.LibrariesCount; num++)
                    {
                        Context.Symbols.Libraries.Add(ClangParser.ConvertLibrary(parserResult.GetLibraries(num)));
                    }
                }
            }

            ClangParser.LibraryParsed -= OnFileParsed;
            Context.Symbols.IndexSymbols();
            SortModulesByDependencies();
            return(true);
        }
示例#5
0
        public bool ParseCode()
        {
            var parser = new ClangParser(new Parser.AST.ASTContext());

            parser.SourceParsed += OnSourceFileParsed;
            parser.ParseProject(Project);

            TargetInfo = parser.GetTargetInfo(Options);

            ASTContext = ClangParser.ConvertASTContext(parser.ASTContext);

            return(true);
        }
示例#6
0
文件: Parser.cs 项目: cDoru/CppSharp
        public ParserResult ParseLibrary(string file)
        {
            var parserOptions = new ParserOptions
            {
                Library      = Library,
                FileName     = file,
                Verbose      = false,
                LibraryDirs  = options.LibraryDirs,
                ToolSetToUse = options.ToolsetToUse
            };

            var result = ClangParser.ParseLibrary(parserOptions);

            OnLibraryParsed(file, result);

            return(result);
        }
示例#7
0
        public bool ParseCode()
        {
            ClangParser.SourcesParsed += OnSourceFileParsed;

            var sourceFiles = Options.Modules.SelectMany(m => m.Headers);

            ParserOptions.BuildForSourceFile(Options.Modules);
            using (ParserResult result = ClangParser.ParseSourceFiles(
                       sourceFiles, ParserOptions))
                Context.TargetInfo = result.TargetInfo;

            Context.ASTContext = ClangParser.ConvertASTContext(ParserOptions.ASTContext);

            ClangParser.SourcesParsed -= OnSourceFileParsed;

            return(!hasParsingErrors);
        }
示例#8
0
        public bool ParseCode()
        {
            var parser = new ClangParser(new Parser.AST.ASTContext());

            parser.SourcesParsed += OnSourceFileParsed;
            parser.ParseProject(Project, Options.UnityBuild);

            foreach (var source in Project.Sources.Where(s => s.Options != null))
            {
                source.Options.Dispose();
            }

            Context.TargetInfo = parser.GetTargetInfo(ParserOptions);
            Context.ASTContext = ClangParser.ConvertASTContext(parser.ASTContext);

            return(!hasParsingErrors);
        }
示例#9
0
        public bool ParseLibraries()
        {
            foreach (var library in Options.Libraries)
            {
                var parser = new ClangParser();
                parser.LibraryParsed += OnFileParsed;

                var res = parser.ParseLibrary(library, Options);

                if (res.Kind != ParserResultKind.Success)
                {
                    continue;
                }

                Symbols.Libraries.Add(ClangParser.ConvertLibrary(res.Library));
            }

            return(true);
        }
示例#10
0
        public bool ParseLibraries()
        {
            ClangParser.LibraryParsed += OnFileParsed;
            foreach (var module in Options.Modules)
            {
                using (var linkerOptions = new LinkerOptions())
                {
                    foreach (var libraryDir in module.LibraryDirs)
                    {
                        linkerOptions.AddLibraryDirs(libraryDir);
                    }

                    foreach (string library in module.Libraries)
                    {
                        if (Context.Symbols.Libraries.Any(l => l.FileName == library))
                        {
                            continue;
                        }
                        linkerOptions.AddLibraries(library);
                    }

                    using (var res = ClangParser.ParseLibrary(linkerOptions))
                    {
                        if (res.Kind != ParserResultKind.Success)
                        {
                            continue;
                        }

                        for (uint i = 0; i < res.LibrariesCount; i++)
                        {
                            Context.Symbols.Libraries.Add(ClangParser.ConvertLibrary(res.GetLibraries(i)));
                        }
                    }
                }
            }
            ClangParser.LibraryParsed -= OnFileParsed;

            Context.Symbols.IndexSymbols();
            SortModulesByDependencies();

            return(true);
        }
示例#11
0
        public bool ParseLibraries()
        {
            foreach (var module in Options.Modules)
            {
                foreach (var libraryDir in module.LibraryDirs)
                {
                    ParserOptions.AddLibraryDirs(libraryDir);
                }

                foreach (var library in module.Libraries)
                {
                    if (Context.Symbols.Libraries.Any(l => l.FileName == library))
                    {
                        continue;
                    }

                    var parser = new ClangParser();
                    parser.LibraryParsed += OnFileParsed;

                    using (var res = parser.ParseLibrary(library, ParserOptions))
                    {
                        if (res.Kind != ParserResultKind.Success)
                        {
                            continue;
                        }

                        Context.Symbols.Libraries.Add(ClangParser.ConvertLibrary(res.Library));

                        res.Library.Dispose();
                    }
                }
            }

            Context.Symbols.IndexSymbols();
            SortModulesByDependencies();

            return(true);
        }
示例#12
0
        public bool ParseCode()
        {
            foreach (var header in Options.Headers)
            {
                var source = Project.AddFile(header);
                source.Options = BuildParseOptions(source);
            }

#if !OLD_PARSER
            var parser = new ClangParser(new Parser.AST.ASTContext());
#else
            var parser = new ClangParser(ASTContext);
#endif

            parser.SourceParsed += OnSourceFileParsed;
            parser.ParseProject(Project, Options);

#if !OLD_PARSER
            ASTContext = ClangParser.ConvertASTContext(parser.ASTContext);
#endif

            return(true);
        }
示例#13
0
        public bool ParseCode()
        {
            var astContext = new Parser.AST.ASTContext();

            var parser = new ClangParser(astContext);

            parser.SourcesParsed += OnSourceFileParsed;

            var sourceFiles = Options.Modules.SelectMany(m => m.Headers);

            if (Options.UnityBuild)
            {
                var parserOptions = BuildParserOptions();
                var result        = parser.ParseSourceFiles(sourceFiles, parserOptions);
                result.Dispose();
            }
            else
            {
                var results = new List <ParserResult>();

                foreach (var sourceFile in sourceFiles)
                {
                    var parserOptions = BuildParserOptions(sourceFile);
                    results.Add(parser.ParseSourceFile(sourceFile, parserOptions));
                }

                foreach (var result in results)
                {
                    result.Dispose();
                }
            }

            Context.TargetInfo = parser.GetTargetInfo(ParserOptions);
            Context.ASTContext = ClangParser.ConvertASTContext(astContext);

            return(!hasParsingErrors);
        }
示例#14
0
文件: Parser.cs 项目: cDoru/CppSharp
        public ParserResult ParseHeader(string file)
        {
            var parserOptions = new ParserOptions
            {
                Library            = Library,
                FileName           = file,
                Verbose            = options.Verbose,
                IncludeDirs        = options.IncludeDirs,
                SystemIncludeDirs  = options.SystemIncludeDirs,
                Defines            = options.Defines,
                NoStandardIncludes = options.NoStandardIncludes,
                NoBuiltinIncludes  = options.NoBuiltinIncludes,
                MicrosoftMode      = options.MicrosoftMode,
                ToolSetToUse       = options.ToolsetToUse,
                TargetTriple       = options.TargetTriple,
                Abi = options.Abi
            };

            var result = ClangParser.ParseHeader(parserOptions);

            OnHeaderParsed(file, result);

            return(result);
        }
示例#15
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine(help);
                return;
            }
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "--include")
                {
                    if (args.Length == i)
                    {
                        Console.WriteLine(help);
                        return;
                    }
                    string includePath = args[i + 1];
                    DirectoryInfo d = new DirectoryInfo(includePath);
                    includes.Add(d.FullName);
                    includePath = Environment.CurrentDirectory + "\\" + includePath;
                    i++;
                }

                if (args[i] == "--namespace")
                {
                    if (args.Length == i)
                    {
                        Console.WriteLine(help);
                        return;
                    }
                    nameSpace = args[i + 1];
                    i++;
                }

                if (args[i] == "--class")
                {
                    if (args.Length == i)
                    {
                        Console.WriteLine(help);
                        return;
                    }
                    className = args[i + 1];
                    i++;
                }

                if (args[i] == "--dll")
                {
                    if (args.Length == i)
                    {
                        Console.WriteLine(help);
                        return;
                    }
                    dllName = args[i + 1];
                    i++;
                }

            }

            sourceFile = args[args.Length - 1];
            if (includes.Count == 0 ||
                string.IsNullOrEmpty(nameSpace) ||
                string.IsNullOrEmpty(className) ||
                string.IsNullOrEmpty(dllName))
            {
                Console.WriteLine(help);
                return;
            }

            string srcFile = Environment.CurrentDirectory + "\\" + sourceFile;
            if(!File.Exists(srcFile))
            {
                Console.WriteLine("Can not find file {0}, working directory {1}", srcFile, Environment.CurrentDirectory);
            }
            ParserOptions options = new ParserOptions();
            options.IncludeDirs.AddRange(includes);
            options.MicrosoftMode = true;
            options.ASTContext = new CppSharp.AST.ASTContext();
            options.FileName = srcFile;
            options.Defines.Add("__STDC_CONSTANT_MACROS");

            SourceFile source = new SourceFile(options.FileName);
            parser = new ClangParser();
            //parser.ASTContext = new CppSharp.AST.ASTContext();
            result = parser.ParseSourceFile(source, options);
            if (result.Kind != ParserResultKind.Success)
            {
                Console.WriteLine("Error: {0}", result.Kind.ToString());
                foreach (var diag in result.Diagnostics)
                    Console.WriteLine(diag.FileName + "(" + diag.LineNumber.ToString() + "):" + diag.Message);
            }

            GenerateInteropFiles(result);

        }
示例#16
0
        public bool ParseCode()
        {
            foreach (var header in Options.Headers)
            {
                var source = Project.AddFile(header);
                source.Options = BuildParseOptions(source);
            }

            #if !OLD_PARSER
            var parser = new ClangParser(new Parser.AST.ASTContext());
            #else
            var parser = new ClangParser(ASTContext);
            #endif

            parser.SourceParsed += OnSourceFileParsed;
            parser.ParseProject(Project, Options);

            TargetInfo = parser.GetTargetInfo(Options);

            #if !OLD_PARSER
            ASTContext = ClangParser.ConvertASTContext(parser.ASTContext);
            #endif

            return true;
        }
示例#17
0
        public bool ParseLibraries()
        {
            foreach (var library in Options.Libraries)
            {
                if (this.Symbols.Libraries.Any(l => l.FileName == library))
                    continue;

                var parser = new ClangParser();
                parser.LibraryParsed += OnFileParsed;

                var res = parser.ParseLibrary(library, Options);

                if (res.Kind != ParserResultKind.Success)
                    continue;

                Symbols.Libraries.Add(ClangParser.ConvertLibrary(res.Library));
            }

            return true;
        }
示例#18
0
        public bool ParseCode()
        {
            var parser = new ClangParser(new Parser.AST.ASTContext());

            parser.SourceParsed += OnSourceFileParsed;
            parser.ParseProject(Project);

            TargetInfo = parser.GetTargetInfo(Options);

            ASTContext = ClangParser.ConvertASTContext(parser.ASTContext);

            return true;
        }
示例#19
0
        public bool ParseLibraries()
        {
            foreach (var library in Options.Libraries)
            {
                var parser = new ClangParser();
                parser.LibraryParsed += OnFileParsed;

                var res = parser.ParseLibrary(library, Options);

                if (res.Kind != ParserResultKind.Success)
                    continue;

            #if !OLD_PARSER
                Symbols.Libraries.Add(ClangParser.ConvertLibrary(res.Library));
            #else
                Symbols.Libraries.Add(res.Library);
            #endif
            }

            return true;
        }
示例#20
0
        public bool ParseLibraries()
        {
            foreach (var module in Options.Modules)
            {
                foreach (var libraryDir in module.LibraryDirs)
                    Options.addLibraryDirs(libraryDir);

                foreach (var library in module.Libraries)
                {
                    if (Symbols.Libraries.Any(l => l.FileName == library))
                        continue;

                    var parser = new ClangParser();
                    parser.LibraryParsed += OnFileParsed;

                    using (var res = parser.ParseLibrary(library, Options))
                    {
                        if (res.Kind != ParserResultKind.Success)
                            continue;

                        Symbols.Libraries.Add(ClangParser.ConvertLibrary(res.Library));

                        res.Library.Dispose();
                    }
                }
            }

            return true;
        }
示例#21
0
        public bool ParseCode()
        {
            var parser = new ClangParser(new Parser.AST.ASTContext());

            parser.SourcesParsed += OnSourceFileParsed;
            parser.ParseProject(Project, Options.UnityBuild);

            TargetInfo = parser.GetTargetInfo(Options);

            ASTContext = ClangParser.ConvertASTContext(parser.ASTContext);

            return !hasParsingErrors;
        }