Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 31202a6

Browse files
authored
Merge pull request #179 from juanjux/fix_sdk
Updates to build with the latest SDK
2 parents cc19741 + e884740 commit 31202a6

File tree

62 files changed

+10239
-6713
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+10239
-6713
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ fixtures/*_got
77
vendor/*
88
__pycache__
99
makebuild.sh
10+
vendor/*

Gopkg.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[[constraint]]
55
name = "gopkg.in/bblfsh/sdk.v2"
6-
version = "2.13.4"
6+
version = "2.14.x"
77

88
[prune]
99
go-tests = true

driver/fixtures/fixtures_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var Suite = &fixtures.Suite{
2727
Semantic: fixtures.SemanticConfig{
2828
BlacklistTypes: []string{
2929
"AsyncFunctionDef",
30+
"Attribute",
3031
"BoolLiteral",
3132
"Bytes",
3233
"FunctionDef",

driver/normalizer/normalizer.go

+144-53
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,43 @@ var Normalize = Transformers([][]Transformer{
2828

2929
func funcDefMap(typ string, async bool) Mapping {
3030
return MapSemantic(typ, uast.FunctionGroup{}, MapObj(
31-
Obj{
32-
"body": Var("body"),
33-
"name": Var("name"),
31+
Fields{
32+
{Name: "body", Op: Var("body")},
33+
{Name: "name", Op: Var("name")},
3434
// Arguments should be converted by the uast.Arguments normalization
35-
"args": Obj{
35+
{Name: "args", Op: Obj{
3636
"args": Var("arguments"),
3737
uast.KeyPos: Var("_pos"),
3838
uast.KeyType: Var("_type"),
39+
}},
40+
// Will be filled only if there is a Python3 type annotation. If the field is
41+
// missing or the value is nil it DOESNT mean that the function returns None,
42+
// just that there is no annotation (but the function could still return some
43+
// other type!).
44+
{Name: "returns", Optional: "ret_opt", Op: Cases("ret_case",
45+
Is(nil),
46+
Obj{
47+
uast.KeyType: String("BoxedName"),
48+
"boxed_value": Var("ret_type"),
49+
// No problem dropping this one, it's used by an internal interpreter optimization/cache
50+
// without semantic meaning
51+
"ctx": Any(),
52+
}),
3953
},
54+
{Name: "decorator_list", Op: Var("func_decorators")},
55+
{Name: "noops_previous", Optional: "np_opt", Op: Var("noops_previous")},
56+
{Name: "noops_sameline", Optional: "ns_opt", Op: Var("noops_sameline")},
4057
},
4158
Obj{
4259
"Nodes": Arr(
43-
Obj{
60+
Fields{
4461
// FIXME: generator=true if it uses yield anywhere in the body
45-
"async": Bool(async),
62+
{Name: "async", Op: Bool(async)},
63+
{Name: "decorators", Op: Var("func_decorators")},
64+
{Name: "comments", Op: Fields{
65+
{Name: "noops_previous", Optional: "np_opt", Op: Var("noops_previous")},
66+
{Name: "noops_sameline", Optional: "ns_opt", Op: Var("noops_sameline")},
67+
}},
4668
},
4769
UASTType(uast.Alias{}, Obj{
4870
// FIXME: can't call identifierWithPos because it would take the position of the
@@ -51,8 +73,17 @@ func funcDefMap(typ string, async bool) Mapping {
5173
"Name": Var("name"),
5274
}),
5375
"Node": UASTType(uast.Function{}, Obj{
54-
"Type": UASTType(uast.FunctionType{}, Obj{
55-
"Arguments": Var("arguments"),
76+
"Type": UASTType(uast.FunctionType{}, Fields{
77+
{Name: "Arguments", Op: Var("arguments")},
78+
{Name: "Returns", Optional: "ret_opt", Op: Cases("ret_case",
79+
// Dont add None here as default, read the comment on the upper
80+
// side of the annotation
81+
Is(nil),
82+
Arr(UASTType(uast.Argument{},
83+
Obj{
84+
"Type": Var("ret_type"),
85+
},
86+
)))},
5687
}),
5788
"Body": UASTType(uast.Block{}, Obj{
5889
"Statements": Var("body"),
@@ -89,7 +120,6 @@ func mapStr(nativeType string) Mapping {
89120
{Name: "boxed_value", Op: UASTType(uast.String{}, Obj{
90121
uast.KeyPos: Var("pos_"),
91122
"Value": Var("s"),
92-
//"Format": String(""),
93123
})},
94124
{Name: "noops_previous", Optional: "np_opt", Op: Var("noops_previous")},
95125
{Name: "noops_sameline", Optional: "ns_opt", Op: Var("noops_sameline")},
@@ -99,9 +129,11 @@ func mapStr(nativeType string) Mapping {
99129

100130
var Normalizers = []Mapping{
101131

102-
// Box Names, Strings, and Bools into a "BoxedFoo" moving the real node to the
132+
// Box Names, Strings, Attributes, and Bools into a "BoxedFoo" moving the real node to the
103133
// "value" property and keeping the comments in the parent (if not, comments would be lost
104-
// when promoting the objects)
134+
// when promoting the objects).
135+
// For other objects, the comments are dropped.
136+
// See: https://github.com/bblfsh/sdk/issues/361
105137
Map(
106138
Part("_", Fields{
107139
{Name: uast.KeyType, Op: String("Name")},
@@ -121,13 +153,10 @@ var Normalizers = []Mapping{
121153
}),
122154
),
123155

124-
// TODO: uncomment after SDK 2.13.x update
125-
// (upgrade currently blocked by: https://github.com/bblfsh/sdk/issues/353)
126156
Map(
127157
Part("_", Fields{
128158
{Name: uast.KeyType, Op: String("BoolLiteral")},
129159
{Name: uast.KeyPos, Op: Var("pos_")},
130-
//{Name: "LiteralValue", Op: Var("lv")},
131160
{Name: "value", Op: Var("lv")},
132161
{Name: "noops_previous", Optional: "np_opt", Op: Var("noops_previous")},
133162
{Name: "noops_sameline", Optional: "ns_opt", Op: Var("noops_sameline")},
@@ -143,6 +172,29 @@ var Normalizers = []Mapping{
143172
}),
144173
),
145174

175+
Map(
176+
Part("_", Fields{
177+
{Name: uast.KeyType, Op: String("Attribute")},
178+
{Name: uast.KeyPos, Op: Var("pos_")},
179+
{Name: "attr", Op: Var("aname")},
180+
// No problem dropping this one, it's used by an internal interpreter optimization
181+
// cache without semantic meaning
182+
// without semantic meaning
183+
{Name: "ctx", Op: Any()},
184+
{Name: "noops_previous", Optional: "np_opt", Op: Var("noops_previous")},
185+
{Name: "noops_sameline", Optional: "ns_opt", Op: Var("noops_sameline")},
186+
}),
187+
Part("_", Fields{
188+
{Name: uast.KeyType, Op: String("BoxedAttribute")},
189+
{Name: "boxed_value", Op: UASTType(uast.Identifier{}, Obj{
190+
uast.KeyPos: Var("pos_"),
191+
"Name": Var("aname"),
192+
})},
193+
{Name: "noops_previous", Optional: "np_opt", Op: Var("noops_previous")},
194+
{Name: "noops_sameline", Optional: "ns_opt", Op: Var("noops_sameline")},
195+
}),
196+
),
197+
146198
mapStr("Bytes"),
147199
mapStr("Str"),
148200
mapStr("StringLiteral"),
@@ -165,6 +217,11 @@ var Normalizers = []Mapping{
165217
AnnotateType("keyword", MapObj(
166218
Fields{
167219
{Name: "arg", Op: Var("name")},
220+
// FIXME: change this once we've a way to store other nodes on semantic objects
221+
// See: https://github.com/bblfsh/sdk/issues/361
222+
// See: https://github.com/bblfsh/python-driver/issues/178
223+
{Name: "noops_previous", Optional: "np_opt", Op: Any()},
224+
{Name: "noops_sameline", Optional: "ns_opt", Op: Any()},
168225
},
169226
Fields{
170227
{Name: "arg",
@@ -174,35 +231,40 @@ var Normalizers = []Mapping{
174231
}),
175232
role.Name),
176233

177-
MapSemantic("Attribute", uast.Identifier{}, MapObj(
178-
Obj{"attr": Var("name")},
179-
Obj{"Name": Var("name")},
180-
)),
181-
182-
MapSemantic("arg", uast.Argument{}, MapObj(
183-
Obj{
184-
uast.KeyToken: Var("name"),
185-
"default": Var("init"),
186-
},
187-
Obj{
188-
"Name": identifierWithPos("name"),
189-
"Init": Var("init"),
190-
},
191-
)),
192-
193234
MapSemantic("arg", uast.Argument{}, MapObj(
194-
Obj{
195-
uast.KeyToken: Var("name"),
235+
Fields{
236+
{Name: uast.KeyToken, Op: Var("name")},
237+
{Name: "default", Optional: "opt_def", Op: Var("init")},
238+
// No problem dropping this one, it's used by an internal interpreter optimization/cache
239+
// without semantic meaning
240+
{Name: "ctx", Optional: "opt_ctx", Op: Any()},
241+
// FIXME: change this once we've a way to store other nodes on semantic objects
242+
// See: https://github.com/bblfsh/sdk/issues/361
243+
// See: https://github.com/bblfsh/python-driver/issues/178
244+
{Name: "noops_previous", Optional: "np_opt", Op: Any()},
245+
{Name: "noops_sameline", Optional: "ns_opt", Op: Any()},
246+
// This one is pesky - they're ignored by the runtime, could have typing from
247+
// mypy, or could have anything else, so we can assign to the semantic type
248+
{Name: "annotation", Optional: "ann_opt", Op: Any()},
196249
},
197-
Obj{
198-
"Name": identifierWithPos("name"),
250+
Fields{
251+
{Name: "Name", Op: identifierWithPos("name")},
252+
{Name: "Init", Optional: "opt_def", Op: Var("init")},
199253
},
200254
)),
201255

202256
MapSemantic("kwonly_arg", uast.Argument{}, MapObj(
203-
Obj{
204-
uast.KeyToken: Var("name"),
205-
"default": Var("init"),
257+
Fields{
258+
{Name: uast.KeyToken, Op: Var("name")},
259+
{Name: "default", Op: Var("init")},
260+
// FIXME: change this once we've a way to store other nodes on semantic objects
261+
// See: https://github.com/bblfsh/sdk/issues/361
262+
// See: https://github.com/bblfsh/python-driver/issues/178
263+
{Name: "noops_previous", Optional: "np_opt", Op: Any()},
264+
{Name: "noops_sameline", Optional: "ns_opt", Op: Any()},
265+
// This one is pesky - they're ignored by the runtime, could have typing from
266+
// mypy, or could have anything else, so we can assign to the semantic type
267+
{Name: "annotation", Op: Any()},
206268
},
207269
Obj{
208270
"Init": Var("init"),
@@ -211,8 +273,16 @@ var Normalizers = []Mapping{
211273
)),
212274

213275
MapSemantic("vararg", uast.Argument{}, MapObj(
214-
Obj{
215-
uast.KeyToken: Var("name"),
276+
Fields{
277+
{Name: uast.KeyToken, Op: Var("name")},
278+
// FIXME: change this once we've a way to store other nodes on semantic objects
279+
// See: https://github.com/bblfsh/sdk/issues/361
280+
// See: https://github.com/bblfsh/python-driver/issues/178
281+
{Name: "noops_previous", Optional: "np_opt", Op: Any()},
282+
{Name: "noops_sameline", Optional: "ns_opt", Op: Any()},
283+
// This one is pesky - they're ignored by the runtime, could have typing from
284+
// mypy, or could have anything else, so we can assign to the semantic type
285+
{Name: "annotation", Op: Any()},
216286
},
217287
Obj{
218288
"Name": identifierWithPos("name"),
@@ -221,12 +291,20 @@ var Normalizers = []Mapping{
221291
)),
222292

223293
MapSemantic("kwarg", uast.Argument{}, MapObj(
224-
Obj{
225-
uast.KeyToken: Var("name"),
294+
Fields{
295+
{Name: uast.KeyToken, Op: Var("name")},
296+
// FIXME: change this once we've a way to store other nodes on semantic objects
297+
// See: https://github.com/bblfsh/sdk/issues/361
298+
// See: https://github.com/bblfsh/python-driver/issues/178
299+
{Name: "noops_previous", Optional: "np_opt", Op: Any()},
300+
{Name: "noops_sameline", Optional: "ns_opt", Op: Any()},
301+
// This one is pesky - they're ignored by the runtime, could have typing from
302+
// mypy, or could have anything else, so we can assign to the semantic type
303+
{Name: "annotation", Op: Any()},
226304
},
227305
Obj{
228-
"Name": identifierWithPos("name"),
229-
"MapVariadic": Bool(true),
306+
"Name": identifierWithPos("name"),
307+
"MapVariadic": Bool(true),
230308
},
231309
)),
232310

@@ -264,14 +342,17 @@ var Normalizers = []Mapping{
264342
Objs{
265343
{"Node": Obj{}},
266344
{
267-
"Node": UASTType(uast.Identifier{}, Obj{"Name": Var("alias")}),
345+
"Node": UASTType(uast.Identifier{},
346+
Obj{
347+
"Name": Var("alias"),
348+
}),
268349
}},
269350
))),
270351

271352
// Star imports
272353
MapSemantic("ImportFrom", uast.RuntimeImport{}, MapObj(
273-
Obj{
274-
"names": Arr(
354+
Fields{
355+
{Name: "names", Op: Arr(
275356
Obj{
276357
uast.KeyType: String("uast:Alias"),
277358
uast.KeyPos: Var("pos"),
@@ -281,9 +362,14 @@ var Normalizers = []Mapping{
281362
},
282363
"Node": Obj{},
283364
},
284-
),
285-
"level": Var("level"),
286-
"module": Var("module"),
365+
)},
366+
{Name: "level", Op: Var("level")},
367+
{Name: "module", Op: Var("module")},
368+
// FIXME: change this once we've a way to store other nodes on semantic objects
369+
// See: https://github.com/bblfsh/sdk/issues/361
370+
// See: https://github.com/bblfsh/python-driver/issues/178
371+
{Name: "noops_previous", Optional: "np_opt", Op: Any()},
372+
{Name: "noops_sameline", Optional: "ns_opt", Op: Any()},
287373
},
288374
Obj{
289375
"All": Bool(true),
@@ -300,10 +386,15 @@ var Normalizers = []Mapping{
300386
)),
301387

302388
MapSemantic("ImportFrom", uast.RuntimeImport{}, MapObj(
303-
Obj{
304-
"names": Var("names"),
305-
"module": Var("module"),
306-
"level": Var("level"),
389+
Fields{
390+
{Name: "names", Op: Var("names")},
391+
{Name: "module", Op: Var("module")},
392+
{Name: "level", Op: Var("level")},
393+
// FIXME: change this once we've a way to store other nodes on semantic objects
394+
// See: https://github.com/bblfsh/sdk/issues/361
395+
// See: https://github.com/bblfsh/python-driver/issues/178
396+
{Name: "noops_previous", Optional: "np_opt", Op: Any()},
397+
{Name: "noops_sameline", Optional: "ns_opt", Op: Any()},
307398
},
308399
Obj{
309400
"Names": Var("names"),

0 commit comments

Comments
 (0)