From 49df5c934e2828eb6380aa755642fd03e31b69a3 Mon Sep 17 00:00:00 2001 From: nanoric Date: Thu, 24 Jan 2019 22:59:43 -0400 Subject: [PATCH] =?UTF-8?q?[Add]=20CXXParser:=20=E5=A2=9E=E5=8A=A0include?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E7=9A=84=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- binding/generator/autocxxpy/cxxparser.py | 32 ++++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/binding/generator/autocxxpy/cxxparser.py b/binding/generator/autocxxpy/cxxparser.py index f5d57f35..1245fac0 100644 --- a/binding/generator/autocxxpy/cxxparser.py +++ b/binding/generator/autocxxpy/cxxparser.py @@ -1,7 +1,7 @@ import logging from collections import defaultdict from dataclasses import dataclass, field -from typing import Any, Dict, List, Optional +from typing import Any, Dict, List, Optional, Sequence from .clang.cindex import ( Config, @@ -169,15 +169,25 @@ class CXXParseResult(Namespace): class CXXFileParser: - def __init__(self, file_path: Optional[str], unsaved_files=None): + def __init__( + self, + file_path: Optional[str], + unsaved_files: Sequence[Sequence[str]] = None, + args: List[str] = None, + ): + if args is None: + args = [] self.unsaved_files = unsaved_files self.file_path = file_path + self.args = args + if "-std=c++11" not in self.args: + self.args.append("-std=c++11") def parse(self) -> CXXParseResult: idx = Index.create() rs = idx.parse( self.file_path, - args="-std=c++11 ".split(" "), + args=self.args, unsaved_files=self.unsaved_files, options=( TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD @@ -422,13 +432,25 @@ class CXXFileParser: class CXXParser(CXXFileParser): - def __init__(self, files: List[str]): + def __init__( + self, + files: Sequence[str], + include_paths: Sequence[str] = None, + args: List[str] = None, + ): + if args is None: + args = [] + if include_paths: + for include_path in include_paths: + args.append("-I" + include_path) dummy_code = "" for file in files: dummy_code += f'#include "{file}"\n' dummy_name = "dummy.cpp" - super().__init__(dummy_name, unsaved_files=[[dummy_name, dummy_code]]) + super().__init__( + dummy_name, unsaved_files=[[dummy_name, dummy_code]], args=args + ) Config.set_library_path("")