2019-01-22 10:15:47 +00:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
from autocxxpy.cxxparser import CXXParser, CXXParseResult
|
|
|
|
from autocxxpy.generator import GeneratorOptions
|
|
|
|
from autocxxpy.preprocessor import PreProcessorResult, PreProcessor
|
|
|
|
|
|
|
|
logger = logging.getLogger(__file__)
|
|
|
|
|
|
|
|
|
|
|
|
def clear_dir(path: str):
|
|
|
|
for file in os.listdir(path):
|
|
|
|
os.unlink(os.path.join(path, file))
|
|
|
|
|
|
|
|
|
|
|
|
class CtpAdaptor:
|
|
|
|
def __init__(self, td_header, md_header):
|
|
|
|
self.td_header = td_header
|
|
|
|
self.md_header = md_header
|
|
|
|
|
|
|
|
def parse(self) -> GeneratorOptions:
|
2019-01-24 09:43:22 +00:00
|
|
|
r0: CXXParseResult = CXXParser(
|
|
|
|
[self.md_header, self.td_header]
|
|
|
|
).parse()
|
2019-01-22 10:15:47 +00:00
|
|
|
r1: PreProcessorResult = PreProcessor(r0).process()
|
|
|
|
|
|
|
|
constants = r0.variables
|
|
|
|
constants.update(r1.const_macros)
|
2019-01-24 09:43:22 +00:00
|
|
|
constants = {
|
|
|
|
k: v for k, v in constants.items() if not k.startswith("_")
|
|
|
|
}
|
2019-01-22 10:15:47 +00:00
|
|
|
|
|
|
|
functions = r0.functions
|
|
|
|
classes = r1.classes
|
|
|
|
|
|
|
|
# make all api "final" to improve performance
|
|
|
|
for c in classes.values():
|
|
|
|
type = c.name[-3:]
|
|
|
|
if type == "Api":
|
|
|
|
for ms in c.functions.values():
|
|
|
|
for m in ms:
|
|
|
|
if m.is_virtual:
|
|
|
|
m.is_pure_virtual = False
|
|
|
|
m.is_final = True
|
2019-01-24 09:43:22 +00:00
|
|
|
elif type == "Spi":
|
2019-01-22 10:15:47 +00:00
|
|
|
for ms in c.functions.values():
|
|
|
|
for m in ms:
|
|
|
|
m.is_virtual = True
|
|
|
|
# m.is_pure_virtual = True
|
|
|
|
m.is_final = False
|
|
|
|
|
|
|
|
options = GeneratorOptions(
|
|
|
|
typedefs=r0.typedefs,
|
|
|
|
constants=constants,
|
|
|
|
functions=functions,
|
|
|
|
classes=classes,
|
|
|
|
dict_classes=r1.dict_classes,
|
|
|
|
enums=r0.enums,
|
|
|
|
)
|
2019-01-24 09:43:22 +00:00
|
|
|
options.includes = ["custom_wrappers/spi.hpp"]
|
2019-01-22 10:15:47 +00:00
|
|
|
return options
|