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

Commit 01eda15

Browse files
Denys Smirnovdennwc
authored andcommitted
normalize return arguments correctly
Signed-off-by: Denys Smirnov <denys@sourced.tech>
1 parent bea9fb3 commit 01eda15

70 files changed

Lines changed: 532 additions & 1694 deletions

File tree

Some content is hidden

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

driver/normalizer/normalizer.go

Lines changed: 120 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,38 @@ var Normalizers = []Mapping{
3131
},
3232
)),
3333
MapSemantic("QualifiedName", uast.QualifiedIdentifier{}, MapObj(
34-
Obj{
35-
"name": Var("name"),
36-
"qualifier": Check(Has{
37-
uast.KeyType: String(uast.TypeOf(uast.Identifier{})),
38-
}, Var("par")),
39-
},
40-
Obj{
41-
"Names": Arr(Var("par"), Var("name")),
42-
},
43-
)),
44-
MapSemantic("QualifiedName", uast.QualifiedIdentifier{}, MapObj(
45-
Obj{
46-
"name": Var("name"),
47-
"qualifier": UASTType(uast.QualifiedIdentifier{}, Obj{
48-
// FIXME: start position
49-
uast.KeyPos: AnyNode(nil),
50-
"Names": Var("names"),
51-
}),
52-
},
53-
Obj{
54-
"Names": Append(Var("names"), Arr(Var("name"))),
55-
},
34+
CasesObj("case",
35+
// common
36+
Obj{"name": Var("name")},
37+
Objs{
38+
// the last name = identifier
39+
{
40+
"qualifier": Check(Has{
41+
uast.KeyType: String(uast.TypeOf(uast.Identifier{})),
42+
}, Var("par")),
43+
},
44+
// linked list
45+
{
46+
"qualifier": UASTType(uast.QualifiedIdentifier{}, Obj{
47+
// FIXME: start position
48+
uast.KeyPos: AnyNode(nil),
49+
"Names": Var("names"),
50+
}),
51+
},
52+
},
53+
),
54+
CasesObj("case", nil,
55+
Objs{
56+
// the last name = identifier
57+
{
58+
"Names": Arr(Var("par"), Var("name")),
59+
},
60+
// linked list
61+
{
62+
"Names": Append(Var("names"), Arr(Var("name"))),
63+
},
64+
},
65+
),
5666
)),
5767
MapSemantic("BlockComment", uast.Comment{}, MapObj(
5868
Obj{
@@ -71,54 +81,88 @@ var Normalizers = []Mapping{
7181
"statements": Var("stmts"),
7282
},
7383
Obj{
74-
"Stmts": Var("stmts"),
84+
"Statements": Var("stmts"),
7585
},
7686
)),
7787
MapSemantic("ImportDeclaration", uast.Import{}, MapObj(
78-
Obj{
79-
"name": Var("name"),
80-
"onDemand": String("true"),
81-
"static": Var("static"),
82-
},
83-
Obj{
84-
"Path": Var("name"),
85-
"All": Bool(true),
86-
"Names": Arr(),
87-
// TODO: handle static when we have scopes
88-
"Scope": Obj{"static": Var("static")},
89-
},
90-
)),
91-
MapSemantic("ImportDeclaration", uast.Import{}, MapObj(
92-
Obj{
93-
"name": Part("path", UASTType(uast.QualifiedIdentifier{}, Obj{
94-
"Names": Append(Var("names"), Arr(Var("name"))),
95-
})),
96-
"onDemand": String("false"),
97-
"static": Var("static"),
98-
},
99-
Obj{
100-
"Path": Part("path", UASTType(uast.QualifiedIdentifier{}, Obj{
101-
"Names": Var("names"),
102-
})),
103-
"All": Bool(false),
104-
"Names": Arr(Var("name")),
105-
// TODO: handle static when we have scopes
106-
"Scope": Obj{"static": Var("static")},
107-
},
88+
CasesObj("case",
89+
// common
90+
Obj{
91+
"static": Var("static"),
92+
},
93+
Objs{
94+
// star import (on demand)
95+
{
96+
"name": Var("name"),
97+
"onDemand": String("true"),
98+
},
99+
// normal import
100+
{
101+
"name": Part("path", UASTType(uast.QualifiedIdentifier{}, Obj{
102+
"Names": Append(Var("names"), Arr(Var("name"))),
103+
})),
104+
"onDemand": String("false"),
105+
},
106+
},
107+
),
108+
CasesObj("case",
109+
// common
110+
Obj{
111+
// TODO: handle static when we have scopes
112+
"Target": Obj{"static": Var("static")},
113+
},
114+
Objs{
115+
// star import (on demand)
116+
{
117+
"Path": Var("name"),
118+
"All": Bool(true),
119+
"Names": Arr(),
120+
},
121+
{
122+
"Path": Part("path", UASTType(uast.QualifiedIdentifier{}, Obj{
123+
"Names": Var("names"),
124+
})),
125+
"All": Bool(false),
126+
"Names": Arr(Var("name")),
127+
},
128+
},
129+
),
108130
)),
109131

110132
MapSemantic("MethodDeclaration", uast.FunctionGroup{}, MapObj(
111133
Obj{
112-
"constructor": Var("constr"),
113-
"extraDimensions2": Is(nil), // TODO: find an example
114-
"javadoc": Var("doc"),
115-
"modifiers": Var("ann"), // TODO: it's an array, we should expand it somewhere
116-
"name": Var("name"),
117-
"body": Var("body"),
118-
"parameters": Var("args"),
119-
"receiverQualifier": Is(nil), // FIXME: handle receiver
120-
"receiverType": Is(nil),
121-
"returnType2": Var("out1"),
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"),
141+
"receiverQualifier": Is(nil), // FIXME: handle receiver
142+
"receiverType": Is(nil),
143+
"returnType2": Cases("out_case",
144+
// no return type (constructor)
145+
Is(nil),
146+
// void
147+
Obj{
148+
uast.KeyType: String("PrimitiveType"),
149+
uast.KeyPos: AnyNode(nil),
150+
"annotations": Is(nil),
151+
"primitiveTypeCode": String("void"),
152+
},
153+
// any other type
154+
Check(
155+
Not(And(
156+
Is(nil),
157+
Has{
158+
uast.KeyType: String("PrimitiveType"),
159+
"annotations": Is(nil),
160+
"primitiveTypeCode": String("void"),
161+
},
162+
)),
163+
Var("out1"),
164+
),
165+
),
122166
"thrownExceptionTypes": Var("exc"),
123167
"typeParameters": Var("tmpl"),
124168
},
@@ -129,18 +173,23 @@ var Normalizers = []Mapping{
129173
UASTType(uast.Alias{}, Obj{
130174
// FIXME: add position
131175
"Name": Var("name"),
132-
"Obj": UASTType(uast.Function{}, Obj{
176+
"Node": UASTType(uast.Function{}, Obj{
133177
"Type": UASTType(uast.FunctionType{}, Obj{
134-
"Args": Var("args"),
135-
"Returns": Arr(
136-
UASTType(uast.Argument{}, Obj{
137-
// TODO: can be void, so should be removed in this case
138-
"Type": Var("out1"),
139-
}),
178+
"Arguments": Var("args"),
179+
"Returns": Cases("out_case",
180+
// no return (constructor)
181+
Is(nil),
182+
// void return
183+
Is(nil),
184+
// normal return type
185+
Arr(
186+
UASTType(uast.Argument{}, Obj{
187+
"Type": Var("out1"),
188+
}),
189+
),
140190
),
141191
}),
142192
"Body": Var("body"),
143-
"Recv": Is(nil),
144193
}),
145194
}),
146195
Obj{ // FIXME: store them as annotations at least

fixtures/anonymous_class_declaration.java.sem.uast

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
},
6262
Name: "testfnc1",
6363
},
64-
Obj: { '@type': "uast:Function",
64+
Node: { '@type': "uast:Function",
6565
Body: { '@type': "uast:Block",
6666
'@pos': { '@type': "uast:Positions",
6767
start: { '@type': "uast:Position",
@@ -75,7 +75,7 @@
7575
col: 47,
7676
},
7777
},
78-
Stmts: [
78+
Statements: [
7979
{ '@type': "ExpressionStatement",
8080
'@role': [Statement],
8181
'@pos': { '@type': "uast:Positions",
@@ -152,7 +152,7 @@
152152
},
153153
Name: "testfnc2",
154154
},
155-
Obj: { '@type': "uast:Function",
155+
Node: { '@type': "uast:Function",
156156
Body: { '@type': "uast:Block",
157157
'@pos': { '@type': "uast:Positions",
158158
start: { '@type': "uast:Position",
@@ -166,32 +166,11 @@
166166
col: 42,
167167
},
168168
},
169-
Stmts: ~,
169+
Statements: ~,
170170
},
171-
Recv: ~,
172171
Type: { '@type': "uast:FunctionType",
173-
Args: ~,
174-
Returns: [
175-
{ '@type': "uast:Argument",
176-
Type: { '@type': "PrimitiveType",
177-
'@token': "void",
178-
'@role': [Primitive, Type],
179-
'@pos': { '@type': "uast:Positions",
180-
start: { '@type': "uast:Position",
181-
offset: 60,
182-
line: 3,
183-
col: 24,
184-
},
185-
end: { '@type': "uast:Position",
186-
offset: 64,
187-
line: 3,
188-
col: 28,
189-
},
190-
},
191-
annotations: ~,
192-
},
193-
},
194-
],
172+
Arguments: ~,
173+
Returns: ~,
195174
},
196175
},
197176
},
@@ -242,30 +221,9 @@
242221
},
243222
],
244223
},
245-
Recv: ~,
246224
Type: { '@type': "uast:FunctionType",
247-
Args: ~,
248-
Returns: [
249-
{ '@type': "uast:Argument",
250-
Type: { '@type': "PrimitiveType",
251-
'@token': "void",
252-
'@role': [Primitive, Type],
253-
'@pos': { '@type': "uast:Positions",
254-
start: { '@type': "uast:Position",
255-
offset: 19,
256-
line: 2,
257-
col: 3,
258-
},
259-
end: { '@type': "uast:Position",
260-
offset: 23,
261-
line: 2,
262-
col: 7,
263-
},
264-
},
265-
annotations: ~,
266-
},
267-
},
268-
],
225+
Arguments: ~,
226+
Returns: ~,
269227
},
270228
},
271229
},

fixtures/array.java.sem.uast

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
},
6262
Name: "code",
6363
},
64-
Obj: { '@type': "uast:Function",
64+
Node: { '@type': "uast:Function",
6565
Body: { '@type': "uast:Block",
6666
'@pos': { '@type': "uast:Positions",
6767
start: { '@type': "uast:Position",
@@ -75,7 +75,7 @@
7575
col: 3,
7676
},
7777
},
78-
Stmts: [
78+
Statements: [
7979
{ '@type': "VariableDeclarationStatement",
8080
'@role': [Declaration, Statement, Variable],
8181
'@pos': { '@type': "uast:Positions",
@@ -373,30 +373,9 @@
373373
},
374374
],
375375
},
376-
Recv: ~,
377376
Type: { '@type': "uast:FunctionType",
378-
Args: ~,
379-
Returns: [
380-
{ '@type': "uast:Argument",
381-
Type: { '@type': "PrimitiveType",
382-
'@token': "void",
383-
'@role': [Primitive, Type],
384-
'@pos': { '@type': "uast:Positions",
385-
start: { '@type': "uast:Position",
386-
offset: 14,
387-
line: 2,
388-
col: 2,
389-
},
390-
end: { '@type': "uast:Position",
391-
offset: 18,
392-
line: 2,
393-
col: 6,
394-
},
395-
},
396-
annotations: ~,
397-
},
398-
},
399-
],
377+
Arguments: ~,
378+
Returns: ~,
400379
},
401380
},
402381
},

0 commit comments

Comments
 (0)