@@ -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 {
0 commit comments