Skip to content

Commit a43ae93

Browse files
Denys Smirnovdennwc
authored andcommitted
handle remaining method fields
Signed-off-by: Denys Smirnov <denys@sourced.tech>
1 parent 56cd6cc commit a43ae93

File tree

91 files changed

+1378
-290
lines changed

Some content is hidden

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

91 files changed

+1378
-290
lines changed

driver/normalizer/normalizer.go

Lines changed: 78 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (op opArrToChain) Construct(st *State, n nodes.Node) (nodes.Node, error) {
167167
return typ, nil
168168
}
169169

170-
func funcDefMap(typ string, returns bool, other Obj) Mapping {
170+
func funcDefMap(typ string, returns bool, other Obj, toGroup ...Op) Mapping {
171171
src := Obj{
172172
"Identifier": Var("name"),
173173
"ParameterList": Obj{
@@ -206,6 +206,45 @@ func funcDefMap(typ string, returns bool, other Obj) Mapping {
206206
}),
207207
)
208208
}
209+
funcGroup := []Op{
210+
Cases("caseAttrs",
211+
Is(nil),
212+
Var("attr"),
213+
Arr(Var("attr")),
214+
),
215+
Cases("caseMods",
216+
Is(nil),
217+
NotEmpty(Var("modifiers")),
218+
),
219+
}
220+
funcGroup = append(funcGroup, toGroup...)
221+
funcGroup = append(funcGroup, UASTType(uast.Alias{}, Obj{
222+
"Name": Var("name"),
223+
"Node": UASTType(uast.Function{}, Obj{
224+
"Type": UASTType(uast.FunctionType{}, dstType),
225+
// If the function was defined with an arrow expression, we will
226+
// generate a uast:Block with a since csharp:Return node containing
227+
// the expression.
228+
"Body": Cases("isArrow",
229+
// case 1: arrow expression
230+
UASTType(uast.Block{}, Obj{
231+
uast.KeyPos: Var("arrow_pos"),
232+
"Statements": Arr(
233+
Obj{
234+
uast.KeyType: String("ReturnStatement"),
235+
uast.KeyPos: Var("arrow_pos_tok"),
236+
"Expression": Var("arrow"),
237+
},
238+
),
239+
}),
240+
// case 2: full body
241+
// TODO(dennwc): this will definitely fail the reverse transform
242+
// make a more specific node check when we need it
243+
// see https://github.com/bblfsh/sdk/issues/355
244+
Var("body"),
245+
),
246+
}),
247+
}))
209248
return MapSemantic(typ, uast.FunctionGroup{}, MapObj(
210249
// Either Body or ExpressionBody will be set.
211250
CasesObj("isArrow",
@@ -241,44 +280,7 @@ func funcDefMap(typ string, returns bool, other Obj) Mapping {
241280
),
242281

243282
Obj{
244-
"Nodes": Arr(
245-
Cases("caseAttrs",
246-
Is(nil),
247-
Var("attr"),
248-
Arr(Var("attr")),
249-
),
250-
Cases("caseMods",
251-
Is(nil),
252-
NotEmpty(Var("modifiers")),
253-
),
254-
UASTType(uast.Alias{}, Obj{
255-
"Name": Var("name"),
256-
"Node": UASTType(uast.Function{}, Obj{
257-
"Type": UASTType(uast.FunctionType{}, dstType),
258-
// If the function was defined with an arrow expression, we will
259-
// generate a uast:Block with a since csharp:Return node containing
260-
// the expression.
261-
"Body": Cases("isArrow",
262-
// case 1: arrow expression
263-
UASTType(uast.Block{}, Obj{
264-
uast.KeyPos: Var("arrow_pos"),
265-
"Statements": Arr(
266-
Obj{
267-
uast.KeyType: String("ReturnStatement"),
268-
uast.KeyPos: Var("arrow_pos_tok"),
269-
"Expression": Var("arrow"),
270-
},
271-
),
272-
}),
273-
// case 2: full body
274-
// TODO(dennwc): this will definitely fail the reverse transform
275-
// make a more specific node check when we need it
276-
// see https://github.com/bblfsh/sdk/issues/355
277-
Var("body"),
278-
),
279-
}),
280-
}),
281-
),
283+
"Nodes": Arr(funcGroup...),
282284
},
283285
))
284286
}
@@ -856,14 +858,31 @@ var Normalizers = []Mapping{
856858
},
857859
)),
858860

859-
funcDefMap("MethodDeclaration", true, Obj{
860-
// number of parameters - safe to ignore
861-
"Arity": Any(),
862-
"ExplicitInterfaceSpecifier": Is(nil),
863-
// FIXME(dennwc): driver drops them currently
864-
"ConstraintClauses": Any(),
865-
"TypeParameterList": Any(),
866-
}),
861+
funcDefMap("MethodDeclaration", true,
862+
Obj{
863+
// number of parameters - safe to ignore
864+
"Arity": Any(),
865+
"ExplicitInterfaceSpecifier": Is(nil),
866+
"ConstraintClauses": Cases("caseConstraint",
867+
Arr(),
868+
NotEmpty(Var("constraints")),
869+
),
870+
"TypeParameterList": Cases("caseTypeParams",
871+
Is(nil),
872+
Arr(),
873+
NotEmpty(Var("typeParams")),
874+
),
875+
},
876+
Cases("caseTypeParams",
877+
Is(nil),
878+
Is(nil),
879+
NotEmpty(Var("typeParams")),
880+
),
881+
Cases("caseConstraint",
882+
Is(nil),
883+
NotEmpty(Var("constraints")),
884+
),
885+
),
867886
// ConstructorDeclaration is similar to MethodDeclaration, but it may include a
868887
// base class initializer that require a special transformation.
869888
MapSemantic("ConstructorDeclaration", uast.FunctionGroup{}, MapObj(
@@ -1226,7 +1245,18 @@ func (op opMergeGroups) checkFuncGroup(st *State, fgroup nodes.Object) (bool, er
12261245
return false, errors.New("expected an array in FuncGroup.Nodes")
12271246
}
12281247
modified := false
1229-
for i, v := range arr {
1248+
for i := 0; i < len(arr); i++ {
1249+
v := arr[i]
1250+
if v == nil {
1251+
// remove nil elements
1252+
if !modified {
1253+
arr = arr.CloneList()
1254+
modified = true
1255+
}
1256+
arr = append(arr[:i], arr[i+1:]...)
1257+
i--
1258+
continue
1259+
}
12301260
// secondary arrays the group annotations/modifiers, etc
12311261
arr2, ok := v.(nodes.Array)
12321262
if !ok {

fixtures/Program.cs.sem.uast

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,6 @@
11011101
},
11021102
},
11031103
Nodes: [
1104-
~,
11051104
[
11061105
{ '@type': "csharp:StaticKeyword",
11071106
'@token': "static",
@@ -4591,7 +4590,6 @@
45914590
},
45924591
},
45934592
Nodes: [
4594-
~,
45954593
[
45964594
{ '@type': "csharp:StaticKeyword",
45974595
'@token': "static",
@@ -5723,7 +5721,6 @@
57235721
},
57245722
},
57255723
Nodes: [
5726-
~,
57275724
[
57285725
{ '@type': "csharp:ProtectedKeyword",
57295726
'@token': "protected",
@@ -9155,7 +9152,6 @@
91559152
},
91569153
},
91579154
Nodes: [
9158-
~,
91599155
[
91609156
{ '@type': "csharp:PublicKeyword",
91619157
'@token': "public",
@@ -9407,7 +9403,6 @@
94079403
},
94089404
},
94099405
Nodes: [
9410-
~,
94119406
[
94129407
{ '@type': "csharp:PublicKeyword",
94139408
'@token': "public",
@@ -9626,7 +9621,6 @@
96269621
},
96279622
},
96289623
Nodes: [
9629-
~,
96309624
[
96319625
{ '@type': "csharp:PublicKeyword",
96329626
'@token': "public",

fixtures/_integration.cs.sem.uast

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@
161161
},
162162
},
163163
Nodes: [
164-
~,
165164
[
166165
{ '@type': "csharp:StaticKeyword",
167166
'@token': "static",

fixtures/accumulator_factory.cs.sem.uast

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124
},
125125
},
126126
Nodes: [
127-
~,
128127
[
129128
{ '@type': "csharp:StaticKeyword",
130129
'@token': "static",
@@ -592,7 +591,6 @@
592591
},
593592
},
594593
Nodes: [
595-
~,
596594
[
597595
{ '@type': "csharp:StaticKeyword",
598596
'@token': "static",

fixtures/anonymous_object.cs.sem.uast

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124
},
125125
},
126126
Nodes: [
127-
~,
128127
[
129128
{ '@type': "csharp:StaticKeyword",
130129
'@token': "static",

fixtures/argument_passtype.cs.sem.uast

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@
124124
},
125125
},
126126
Nodes: [
127-
~,
128-
~,
129127
{ '@type': "uast:Alias",
130128
Name: { '@type': "uast:Identifier",
131129
'@pos': { '@type': "uast:Positions",

fixtures/arithmetic_ops.cs.sem.uast

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124
},
125125
},
126126
Nodes: [
127-
~,
128127
[
129128
{ '@type': "csharp:StaticKeyword",
130129
'@token': "static",

fixtures/array_literal.cs.sem.uast

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124
},
125125
},
126126
Nodes: [
127-
~,
128127
[
129128
{ '@type': "csharp:StaticKeyword",
130129
'@token': "static",

fixtures/array_stackalloc.cs.sem.uast

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@
201201
},
202202
},
203203
Nodes: [
204-
~,
205204
[
206205
{ '@type': "csharp:UnsafeKeyword",
207206
'@token': "unsafe",

fixtures/as.cs.sem.uast

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124
},
125125
},
126126
Nodes: [
127-
~,
128127
[
129128
{ '@type': "csharp:PublicKeyword",
130129
'@token': "public",
@@ -639,7 +638,6 @@
639638
},
640639
},
641640
Nodes: [
642-
~,
643641
[
644642
{ '@type': "csharp:StaticKeyword",
645643
'@token': "static",

0 commit comments

Comments
 (0)