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