[Mod] CXXParser与CXXFileParser互换名字
This commit is contained in:
parent
49df5c934e
commit
9e7e4185a7
@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from autocxxpy.cxxparser import CXXParser, CXXParseResult
|
from autocxxpy.cxxparser import CXXFileParser, CXXParseResult
|
||||||
from autocxxpy.generator import GeneratorOptions
|
from autocxxpy.generator import GeneratorOptions
|
||||||
from autocxxpy.preprocessor import PreProcessorResult, PreProcessor
|
from autocxxpy.preprocessor import PreProcessorResult, PreProcessor
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ class CtpAdaptor:
|
|||||||
self.md_header = md_header
|
self.md_header = md_header
|
||||||
|
|
||||||
def parse(self) -> GeneratorOptions:
|
def parse(self) -> GeneratorOptions:
|
||||||
r0: CXXParseResult = CXXParser(
|
r0: CXXParseResult = CXXFileParser(
|
||||||
[self.md_header, self.td_header]
|
[self.md_header, self.td_header]
|
||||||
).parse()
|
).parse()
|
||||||
r1: PreProcessorResult = PreProcessor(r0).process()
|
r1: PreProcessorResult = PreProcessor(r0).process()
|
||||||
|
@ -168,7 +168,7 @@ class CXXParseResult(Namespace):
|
|||||||
macros: Dict[str, str] = field(default_factory=dict)
|
macros: Dict[str, str] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
class CXXFileParser:
|
class CXXParser:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
file_path: Optional[str],
|
file_path: Optional[str],
|
||||||
@ -199,27 +199,27 @@ class CXXFileParser:
|
|||||||
# todo: parse namespace
|
# todo: parse namespace
|
||||||
for c in rs.cursor.walk_preorder():
|
for c in rs.cursor.walk_preorder():
|
||||||
if c.kind == CursorKind.FUNCTION_DECL:
|
if c.kind == CursorKind.FUNCTION_DECL:
|
||||||
func = CXXFileParser._process_function(c)
|
func = CXXParser._process_function(c)
|
||||||
result.functions[func.name] = func
|
result.functions[func.name] = func
|
||||||
elif c.kind == CursorKind.ENUM_DECL:
|
elif c.kind == CursorKind.ENUM_DECL:
|
||||||
e = CXXFileParser._process_enum(c)
|
e = CXXParser._process_enum(c)
|
||||||
result.enums[e.name] = e
|
result.enums[e.name] = e
|
||||||
elif (
|
elif (
|
||||||
c.kind == CursorKind.CLASS_DECL
|
c.kind == CursorKind.CLASS_DECL
|
||||||
or c.kind == CursorKind.STRUCT_DECL
|
or c.kind == CursorKind.STRUCT_DECL
|
||||||
):
|
):
|
||||||
class_ = CXXFileParser._process_class(c)
|
class_ = CXXParser._process_class(c)
|
||||||
cname = class_.name
|
cname = class_.name
|
||||||
result.classes[cname] = class_
|
result.classes[cname] = class_
|
||||||
elif c.kind == CursorKind.VAR_DECL:
|
elif c.kind == CursorKind.VAR_DECL:
|
||||||
name, value = CXXFileParser._process_variable(c)
|
name, value = CXXParser._process_variable(c)
|
||||||
if value:
|
if value:
|
||||||
result.variables[name] = value
|
result.variables[name] = value
|
||||||
elif c.kind == CursorKind.TYPEDEF_DECL:
|
elif c.kind == CursorKind.TYPEDEF_DECL:
|
||||||
name, target = CXXFileParser._process_typedef(c)
|
name, target = CXXParser._process_typedef(c)
|
||||||
result.typedefs[name] = target
|
result.typedefs[name] = target
|
||||||
elif c.kind == CursorKind.MACRO_DEFINITION:
|
elif c.kind == CursorKind.MACRO_DEFINITION:
|
||||||
name, definition = CXXFileParser._process_macro_definition(c)
|
name, definition = CXXParser._process_macro_definition(c)
|
||||||
result.macros[name] = definition
|
result.macros[name] = definition
|
||||||
elif (
|
elif (
|
||||||
False
|
False
|
||||||
@ -236,7 +236,7 @@ class CXXFileParser:
|
|||||||
# ignore any body
|
# ignore any body
|
||||||
pass
|
pass
|
||||||
elif (
|
elif (
|
||||||
CXXFileParser._is_literal_cursor(c)
|
CXXParser._is_literal_cursor(c)
|
||||||
or c.kind == CursorKind.MACRO_INSTANTIATION
|
or c.kind == CursorKind.MACRO_INSTANTIATION
|
||||||
or c.kind == CursorKind.INCLUSION_DIRECTIVE
|
or c.kind == CursorKind.INCLUSION_DIRECTIVE
|
||||||
):
|
):
|
||||||
@ -307,12 +307,12 @@ class CXXFileParser:
|
|||||||
class_ = Class(name=c.displayname)
|
class_ = Class(name=c.displayname)
|
||||||
for ac in c.get_children():
|
for ac in c.get_children():
|
||||||
if ac.kind == CursorKind.CONSTRUCTOR:
|
if ac.kind == CursorKind.CONSTRUCTOR:
|
||||||
func = CXXFileParser._process_method(ac, class_)
|
func = CXXParser._process_method(ac, class_)
|
||||||
if func.is_virtual:
|
if func.is_virtual:
|
||||||
class_.is_polymorphic = True
|
class_.is_polymorphic = True
|
||||||
class_.constructors = func
|
class_.constructors = func
|
||||||
elif ac.kind == CursorKind.DESTRUCTOR:
|
elif ac.kind == CursorKind.DESTRUCTOR:
|
||||||
func = CXXFileParser._process_method(ac, class_)
|
func = CXXParser._process_method(ac, class_)
|
||||||
if func.is_virtual:
|
if func.is_virtual:
|
||||||
class_.is_polymorphic = True
|
class_.is_polymorphic = True
|
||||||
class_.destructor = func
|
class_.destructor = func
|
||||||
@ -320,7 +320,7 @@ class CXXFileParser:
|
|||||||
v = Variable(ac.spelling, ac.type.spelling)
|
v = Variable(ac.spelling, ac.type.spelling)
|
||||||
class_.variables[v.name] = v
|
class_.variables[v.name] = v
|
||||||
elif ac.kind == CursorKind.CXX_METHOD:
|
elif ac.kind == CursorKind.CXX_METHOD:
|
||||||
func = CXXFileParser._process_method(ac, class_)
|
func = CXXParser._process_method(ac, class_)
|
||||||
if func.is_virtual:
|
if func.is_virtual:
|
||||||
class_.is_polymorphic = True
|
class_.is_polymorphic = True
|
||||||
class_.functions[func.name].append(func)
|
class_.functions[func.name].append(func)
|
||||||
@ -349,8 +349,8 @@ class CXXFileParser:
|
|||||||
length = len(children)
|
length = len(children)
|
||||||
if length == 1:
|
if length == 1:
|
||||||
child = children[0]
|
child = children[0]
|
||||||
if CXXFileParser._is_literal_cursor(child):
|
if CXXParser._is_literal_cursor(child):
|
||||||
value = CXXFileParser._process_literal(child)
|
value = CXXParser._process_literal(child)
|
||||||
return c.spelling, value
|
return c.spelling, value
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"unable to process variable : %s %s", c.spelling, c.extent
|
"unable to process variable : %s %s", c.spelling, c.extent
|
||||||
@ -378,7 +378,7 @@ class CXXFileParser:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_source(token: Token, encoding="utf-8"):
|
def _get_source(token: Token, encoding="utf-8"):
|
||||||
return CXXFileParser._get_source_from_file(
|
return CXXParser._get_source_from_file(
|
||||||
token.location.file.name,
|
token.location.file.name,
|
||||||
token.extent.start.offset,
|
token.extent.start.offset,
|
||||||
token.extent.end.offset,
|
token.extent.end.offset,
|
||||||
@ -400,7 +400,7 @@ class CXXFileParser:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _is_literal_cursor(c: Cursor):
|
def _is_literal_cursor(c: Cursor):
|
||||||
return c.kind in CXXFileParser.LITERAL_KINDS
|
return c.kind in CXXParser.LITERAL_KINDS
|
||||||
# return str(c)[-9:-1] == 'LITERAL'
|
# return str(c)[-9:-1] == 'LITERAL'
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -413,7 +413,7 @@ class CXXFileParser:
|
|||||||
elif c.kind == CursorKind.STRING_LITERAL:
|
elif c.kind == CursorKind.STRING_LITERAL:
|
||||||
return str(spelling)
|
return str(spelling)
|
||||||
elif c.kind == CursorKind.CHARACTER_LITERAL:
|
elif c.kind == CursorKind.CHARACTER_LITERAL:
|
||||||
return CXXFileParser.character_literal_to_int(spelling)
|
return CXXParser.character_literal_to_int(spelling)
|
||||||
elif c.kind == CursorKind.FLOATING_LITERAL:
|
elif c.kind == CursorKind.FLOATING_LITERAL:
|
||||||
return float(spelling)
|
return float(spelling)
|
||||||
logger.warning(
|
logger.warning(
|
||||||
@ -431,7 +431,7 @@ class CXXFileParser:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CXXParser(CXXFileParser):
|
class CXXFileParser(CXXParser):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
files: Sequence[str],
|
files: Sequence[str],
|
||||||
|
Loading…
Reference in New Issue
Block a user