2020-11-05 14:30:52 +08:00
|
|
|
#!python
|
|
|
|
# from gen_base_visitor import *
|
|
|
|
# from gen_node import *
|
|
|
|
from assemble import *
|
|
|
|
from meta_gen import *
|
2020-11-06 15:34:39 +08:00
|
|
|
import re
|
|
|
|
import os
|
2020-11-05 14:30:52 +08:00
|
|
|
|
|
|
|
def gen_file(rootfile, template, output, **kwargs):
|
|
|
|
namespace, root_base, struct_name = meta_gen(readfile(rootfile))
|
|
|
|
vc = assemble(readfile(template), namespace=namespace, root_base=root_base, struct_name=struct_name, **kwargs)
|
|
|
|
file = open(output, 'w')
|
2020-11-24 21:28:38 +08:00
|
|
|
license = open("../../internal/core/build-support/cpp_license.txt").read()
|
|
|
|
file.write(license + vc)
|
2020-11-05 14:30:52 +08:00
|
|
|
|
2020-11-06 15:34:39 +08:00
|
|
|
|
|
|
|
def extract_extra_body(visitor_info, query_path):
|
2020-11-16 10:55:49 +08:00
|
|
|
pattern = re.compile(r"class(.*){\n((.|\n)*?)\n};", re.MULTILINE)
|
2020-11-06 15:34:39 +08:00
|
|
|
|
|
|
|
for node, visitors in visitor_info.items():
|
|
|
|
for visitor in visitors:
|
|
|
|
vis_name = visitor['visitor_name']
|
|
|
|
vis_file = query_path + "visitors/" + vis_name + ".cpp"
|
|
|
|
body = ' public:'
|
|
|
|
|
2020-11-16 10:55:49 +08:00
|
|
|
inc_pattern_str = r'^(#include(.|\n)*)\n#include "query/generated/{}.h"'.format(vis_name)
|
|
|
|
inc_pattern = re.compile(inc_pattern_str, re.MULTILINE)
|
|
|
|
|
2020-11-06 15:34:39 +08:00
|
|
|
if os.path.exists(vis_file):
|
2020-11-16 10:55:49 +08:00
|
|
|
content = readfile(vis_file)
|
|
|
|
infos = pattern.findall(content)
|
|
|
|
assert len(infos) <= 1
|
2020-11-06 15:34:39 +08:00
|
|
|
if len(infos) == 1:
|
|
|
|
name, body, _ = infos[0]
|
2020-11-16 10:55:49 +08:00
|
|
|
|
|
|
|
extra_inc_infos = inc_pattern.findall(content)
|
|
|
|
assert(len(extra_inc_infos) <= 1)
|
|
|
|
print(extra_inc_infos)
|
|
|
|
if len(extra_inc_infos) == 1:
|
|
|
|
extra_inc_body, _ = extra_inc_infos[0]
|
|
|
|
|
2020-11-06 15:34:39 +08:00
|
|
|
visitor["ctor_and_member"] = body
|
2020-11-16 10:55:49 +08:00
|
|
|
visitor["extra_inc"] = extra_inc_body
|
2020-11-06 15:34:39 +08:00
|
|
|
|
2020-11-05 14:30:52 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
query_path = "../../internal/core/src/query/"
|
|
|
|
output_path = query_path + "generated/"
|
|
|
|
|
|
|
|
|
|
|
|
node_names = ["Expr", "PlanNode"]
|
|
|
|
visitor_info = {
|
2020-11-19 10:46:17 +08:00
|
|
|
'Expr': [
|
|
|
|
{
|
|
|
|
'visitor_name': "ShowExprVisitor",
|
|
|
|
"parameter_name": 'expr',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'visitor_name': "ExecExprVisitor",
|
|
|
|
"parameter_name": 'expr',
|
|
|
|
},
|
2021-01-06 14:45:50 +08:00
|
|
|
{
|
|
|
|
'visitor_name': "VerifyExprVisitor",
|
|
|
|
"parameter_name": 'expr',
|
|
|
|
},
|
2021-01-26 09:38:40 +08:00
|
|
|
{
|
|
|
|
'visitor_name': "ExtractInfoExprVisitor",
|
|
|
|
"parameter_name": 'expr',
|
|
|
|
},
|
2020-11-19 10:46:17 +08:00
|
|
|
],
|
2020-11-06 15:34:39 +08:00
|
|
|
'PlanNode': [
|
|
|
|
{
|
|
|
|
'visitor_name': "ShowPlanNodeVisitor",
|
|
|
|
"parameter_name": 'node',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'visitor_name': "ExecPlanNodeVisitor",
|
|
|
|
"parameter_name": 'node',
|
|
|
|
},
|
2021-01-06 14:45:50 +08:00
|
|
|
{
|
|
|
|
'visitor_name': "VerifyPlanNodeVisitor",
|
|
|
|
"parameter_name": 'node',
|
|
|
|
},
|
2021-01-26 09:38:40 +08:00
|
|
|
{
|
|
|
|
'visitor_name': "ExtractInfoPlanNodeVisitor",
|
|
|
|
"parameter_name": 'node',
|
|
|
|
},
|
2020-11-06 15:34:39 +08:00
|
|
|
]
|
2020-11-05 14:30:52 +08:00
|
|
|
}
|
2020-11-06 15:34:39 +08:00
|
|
|
extract_extra_body(visitor_info, query_path)
|
2020-11-05 14:30:52 +08:00
|
|
|
|
|
|
|
for name in node_names:
|
|
|
|
rootfile = query_path + name + ".h"
|
|
|
|
|
|
|
|
template = 'templates/visitor_base.h'
|
|
|
|
output = output_path + name + 'Visitor.h'
|
|
|
|
gen_file(rootfile, template, output)
|
|
|
|
|
|
|
|
template = 'templates/node_def.cpp'
|
|
|
|
output = output_path + name + '.cpp'
|
|
|
|
gen_file(rootfile, template, output)
|
|
|
|
|
|
|
|
for info in visitor_info[name]:
|
|
|
|
vis_name = info['visitor_name']
|
|
|
|
template = 'templates/visitor_derived.h'
|
|
|
|
output = output_path + vis_name + '.h'
|
|
|
|
gen_file(rootfile, template, output, **info)
|
|
|
|
|
|
|
|
vis_name = info['visitor_name']
|
|
|
|
template = 'templates/visitor_derived.cpp'
|
|
|
|
output = output_path + vis_name + '.cpp'
|
|
|
|
gen_file(rootfile, template, output, **info)
|
|
|
|
print("Done")
|