-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype_raising.py
104 lines (88 loc) · 2.87 KB
/
type_raising.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#coding=utf-8
from node import Node
from utils import get_opt
from opt_class import *
from class_file import cClass
import re
def fill_in_slot(opt,param,prefix):
# c --> F F:count(c) c string, F:sum(c) c number
# V --> Filter:In(c=V.c,V)
# T --> F F:count(T)
# D --> Filter:In(c=D.c,V)
if type(opt) == Sum or type(opt) == Max or type(opt) == Min or type(opt) == Avg: #一个参数
if param.c_type == 'number': #sum操作
opt.param.val = param
opt.c_name = param.c_name
opt.t_name = param.t_name
opt.c_type = param.c_type
else:
return None
elif type(opt) == Count:
if param.value == 'T': #如果是T参数随意
opt.param.val = param
opt.c_name = 'count(t)'
opt.t_name = param.t_name
opt.c_type = 'number'
else:
opt.param.val = param
opt.c_name = param.c_name
opt.t_name = param.t_name
opt.c_type = 'number'
elif type(opt) == In:
# 第一个参数是c
c = cClass(param.t_name, param.c_name, param.c_type, param.t_name + '.' + param.c_name)
opt.param_1.val = c
opt.param_2.val = param
opt.t_name = param.t_name
opt.c_name = param.c_name
opt.c_type = param.c_type
#opt.value = prefix
opt.value = prefix
return opt
# c --> F F:count(c) c string, F:sum(c) c number
def createVal(gnode, optype, child, prefix=""):
opt = extract_opt(optype)
cls = get_opt(opt) #count or select
if cls == None:
raise("Error OPtion {0}".format(opt))
cls = fill_in_slot(cls,child.val,prefix)
return cls
def extract_opt(opt):
if '(' not in opt:
return ""
#去除括号
new_opt = ''
for i in range(len(opt)):
if opt[i] != '(':
new_opt += opt[i]
else:
return new_opt
def extract_paramter(func):
if '(' not in func:return None
arg = re.search('\(.*\)', func).group()[1:-1].split(',')
return arg
def format_(l):
args = [extract_paramter(i) for i in l.split('.')]
a = []
for i in range(len(args)):
if args[i] != None: a.extend(args[i])
if len(a) == 1: return a[0]
else:return ",".join(a)
def type_rasing(gDict, nodelist, start, end, key=""):
values = []
for node in nodelist:
values.append(node.val.value)
for value in values:
#有lambda 和 没有lambda
if value == None:
print(key)
exit(100)
for rhs, lhs, func in gDict:
if rhs == value:
index = values.index(rhs)
option = createVal(lhs, func, nodelist[index], lhs)
if option == None: continue
values.append(lhs)
node = Node(nodelist[index], None, option, start, end)
nodelist.append(node)
return nodelist