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

Commit 913b7d1

Browse files
Denys Smirnovdennwc
authored andcommitted
fix normalization of arguments
Signed-off-by: Denys Smirnov <denys@sourced.tech>
1 parent 50221ee commit 913b7d1

15 files changed

Lines changed: 178 additions & 206 deletions

driver/normalizer/normalizer.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,23 @@ var Normalizers = []Mapping{
131131

132132
MapSemantic("MethodDeclaration", uast.FunctionGroup{}, MapObj(
133133
Obj{
134-
"constructor": Var("constr"),
135-
"extraDimensions2": Is(nil), // TODO: find an example
136-
"javadoc": Var("doc"),
137-
"modifiers": Var("ann"), // TODO: it's an array, we should expand it somewhere
138-
"name": Var("name"),
139-
"body": Var("body"),
140-
"parameters": Var("args"),
134+
"constructor": Var("constr"),
135+
"extraDimensions2": Is(nil), // TODO: find an example
136+
"javadoc": Var("doc"),
137+
"modifiers": Var("ann"), // TODO: it's an array, we should expand it somewhere
138+
"name": Var("name"),
139+
"body": Var("body"),
140+
"parameters": Each("args", Obj{
141+
uast.KeyType: String("SingleVariableDeclaration"),
142+
uast.KeyPos: Var("apos"),
143+
"extraDimensions2": Is(nil),
144+
"initializer": Var("ainit"),
145+
"modifiers": Is(nil),
146+
"name": Var("aname"),
147+
"type": Var("atype"),
148+
"varargs": Cases("varg", String("false"), String("true")),
149+
"varargsAnnotations": Is(nil),
150+
}),
141151
"receiverQualifier": Is(nil), // FIXME: handle receiver
142152
"receiverType": Is(nil),
143153
"returnType2": Cases("out_case",
@@ -175,7 +185,13 @@ var Normalizers = []Mapping{
175185
"Name": Var("name"),
176186
"Node": UASTType(uast.Function{}, Obj{
177187
"Type": UASTType(uast.FunctionType{}, Obj{
178-
"Arguments": Var("args"),
188+
"Arguments": Each("args", UASTType(uast.Argument{}, Obj{
189+
uast.KeyPos: Var("apos"),
190+
"Name": Var("aname"),
191+
"Type": Var("atype"),
192+
"Init": Var("ainit"),
193+
"Variadic": Cases("varg", Bool(false), Bool(true)),
194+
})),
179195
"Returns": Cases("out_case",
180196
// no return (constructor)
181197
Is(nil),

fixtures/constructor_invocation.java.sem.uast

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@
175175
},
176176
Type: { '@type': "uast:FunctionType",
177177
Arguments: [
178-
{ '@type': "SingleVariableDeclaration",
179-
'@role': [Declaration, Variable],
178+
{ '@type': "uast:Argument",
180179
'@pos': { '@type': "uast:Positions",
181180
start: { '@type': "uast:Position",
182181
offset: 48,
@@ -189,10 +188,9 @@
189188
col: 13,
190189
},
191190
},
192-
'extraDimensions2': ~,
193-
initializer: ~,
194-
modifiers: ~,
195-
name: { '@type': "uast:Identifier",
191+
Init: ~,
192+
MapVariadic: false,
193+
Name: { '@type': "uast:Identifier",
196194
'@pos': { '@type': "uast:Positions",
197195
start: { '@type': "uast:Position",
198196
offset: 52,
@@ -207,7 +205,8 @@
207205
},
208206
Name: "i",
209207
},
210-
type: { '@type': "PrimitiveType",
208+
Receiver: false,
209+
Type: { '@type': "PrimitiveType",
211210
'@token': "int",
212211
'@role': [Primitive, Type],
213212
'@pos': { '@type': "uast:Positions",
@@ -224,8 +223,7 @@
224223
},
225224
annotations: ~,
226225
},
227-
varargs: "false",
228-
varargsAnnotations: ~,
226+
Variadic: false,
229227
},
230228
],
231229
Returns: ~,

fixtures/hello_world.java.sem.uast

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@
226226
},
227227
Type: { '@type': "uast:FunctionType",
228228
Arguments: [
229-
{ '@type': "SingleVariableDeclaration",
230-
'@role': [Declaration, Variable],
229+
{ '@type': "uast:Argument",
231230
'@pos': { '@type': "uast:Positions",
232231
start: { '@type': "uast:Position",
233232
offset: 39,
@@ -240,10 +239,9 @@
240239
col: 39,
241240
},
242241
},
243-
'extraDimensions2': ~,
244-
initializer: ~,
245-
modifiers: ~,
246-
name: { '@type': "uast:Identifier",
242+
Init: ~,
243+
MapVariadic: false,
244+
Name: { '@type': "uast:Identifier",
247245
'@pos': { '@type': "uast:Positions",
248246
start: { '@type': "uast:Position",
249247
offset: 48,
@@ -258,7 +256,8 @@
258256
},
259257
Name: "args",
260258
},
261-
type: { '@type': "ArrayType",
259+
Receiver: false,
260+
Type: { '@type': "ArrayType",
262261
'@role': [List, Primitive, Type],
263262
'@pos': { '@type': "uast:Positions",
264263
start: { '@type': "uast:Position",
@@ -322,8 +321,7 @@
322321
},
323322
},
324323
},
325-
varargs: "false",
326-
varargsAnnotations: ~,
324+
Variadic: false,
327325
},
328326
],
329327
Returns: ~,

fixtures/intersection_type.java.sem.uast

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@
285285
},
286286
Type: { '@type': "uast:FunctionType",
287287
Arguments: [
288-
{ '@type': "SingleVariableDeclaration",
289-
'@role': [Declaration, Variable],
288+
{ '@type': "uast:Argument",
290289
'@pos': { '@type': "uast:Positions",
291290
start: { '@type': "uast:Position",
292291
offset: 54,
@@ -299,10 +298,9 @@
299298
col: 45,
300299
},
301300
},
302-
'extraDimensions2': ~,
303-
initializer: ~,
304-
modifiers: ~,
305-
name: { '@type': "uast:Identifier",
301+
Init: ~,
302+
MapVariadic: false,
303+
Name: { '@type': "uast:Identifier",
306304
'@pos': { '@type': "uast:Positions",
307305
start: { '@type': "uast:Position",
308306
offset: 56,
@@ -317,7 +315,8 @@
317315
},
318316
Name: "a",
319317
},
320-
type: { '@type': "SimpleType",
318+
Receiver: false,
319+
Type: { '@type': "SimpleType",
321320
'@role': [Type],
322321
'@pos': { '@type': "uast:Positions",
323322
start: { '@type': "uast:Position",
@@ -348,8 +347,7 @@
348347
Name: "I",
349348
},
350349
},
351-
varargs: "false",
352-
varargsAnnotations: ~,
350+
Variadic: false,
353351
},
354352
],
355353
Returns: ~,

fixtures/lambda_expession.java.sem.uast

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@
6565
Body: ~,
6666
Type: { '@type': "uast:FunctionType",
6767
Arguments: [
68-
{ '@type': "SingleVariableDeclaration",
69-
'@role': [Declaration, Variable],
68+
{ '@type': "uast:Argument",
7069
'@pos': { '@type': "uast:Positions",
7170
start: { '@type': "uast:Position",
7271
offset: 21,
@@ -79,10 +78,9 @@
7978
col: 14,
8079
},
8180
},
82-
'extraDimensions2': ~,
83-
initializer: ~,
84-
modifiers: ~,
85-
name: { '@type': "uast:Identifier",
81+
Init: ~,
82+
MapVariadic: false,
83+
Name: { '@type': "uast:Identifier",
8684
'@pos': { '@type': "uast:Positions",
8785
start: { '@type': "uast:Position",
8886
offset: 25,
@@ -97,7 +95,8 @@
9795
},
9896
Name: "a",
9997
},
100-
type: { '@type': "PrimitiveType",
98+
Receiver: false,
99+
Type: { '@type': "PrimitiveType",
101100
'@token': "int",
102101
'@role': [Primitive, Type],
103102
'@pos': { '@type': "uast:Positions",
@@ -114,8 +113,7 @@
114113
},
115114
annotations: ~,
116115
},
117-
varargs: "false",
118-
varargsAnnotations: ~,
116+
Variadic: false,
119117
},
120118
],
121119
Returns: [

0 commit comments

Comments
 (0)