@@ -167,6 +167,14 @@ func (op opArrToChain) Construct(st *State, n nodes.Node) (nodes.Node, error) {
167167 return typ , nil
168168}
169169
170+ // funcDefMap creates a common annotation structure for methods with a specified AST type.
171+ //
172+ // If returns flag is set, it will also convert the return value of the method, in other
173+ // cases it will assume that there should be no ReturnType in the native AST node.
174+ //
175+ // Other object allows to remap custom fields from the native AST. Other fields can be
176+ // either asserted to a specific value, or stored to a variable and restored in the
177+ // FunctionGroup array using toGroup.
170178func funcDefMap (typ string , returns bool , other Obj , toGroup ... Op ) Mapping {
171179 src := Obj {
172180 "Identifier" : Var ("name" ),
@@ -222,9 +230,8 @@ func funcDefMap(typ string, returns bool, other Obj, toGroup ...Op) Mapping {
222230 "Name" : Var ("name" ),
223231 "Node" : UASTType (uast.Function {}, Obj {
224232 "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.
233+ // If the function was defined with an arrow expression, we will generate
234+ // a uast:Block with a csharp:Return node containing the expression.
228235 "Body" : Cases ("isArrow" ,
229236 // case 1: arrow expression
230237 UASTType (uast.Block {}, Obj {
@@ -1190,6 +1197,8 @@ func (op opMergeGroups) Kinds() nodes.Kind {
11901197// Check tests if a current node is uast:Group and uast:FuncGroup and contains group of
11911198// another kind. It will remove the second group and merge children into current one.
11921199// uast:FuncGroup is preferred.
1200+ //
1201+ // See https://github.com/bblfsh/sdk/issues/361.
11931202func (op opMergeGroups ) Check (st * State , n nodes.Node ) (bool , error ) {
11941203 group , ok := n .(nodes.Object )
11951204 if ! ok {
@@ -1205,7 +1214,8 @@ func (op opMergeGroups) Check(st *State, n nodes.Node) (bool, error) {
12051214}
12061215
12071216// checkGroup tests if the current node is uast:Group and if it contains a uast:FunctionGroup
1208- // node, it will remove the current node and merge other children into the FunctionGroup.
1217+ // node, it will rebuild the node by removing the current node and merge other children into
1218+ // the FunctionGroup. The changed node will be passed to the sub-operation.
12091219func (op opMergeGroups ) checkGroup (st * State , group nodes.Object ) (bool , error ) {
12101220 arr , ok := group ["Nodes" ].(nodes.Array )
12111221 if ! ok {
@@ -1237,7 +1247,7 @@ func (op opMergeGroups) checkGroup(st *State, group nodes.Object) (bool, error)
12371247}
12381248
12391249// checkFuncGroup tests if the current node is uast:FuncGroup and if any of its sub-arrays
1240- // contain a ust :Group, it will be removed and the children will be flattened into a sub-array.
1250+ // contain a uast :Group, it will be removed and the children will be flattened into a sub-array.
12411251func (op opMergeGroups ) checkFuncGroup (st * State , fgroup nodes.Object ) (bool , error ) {
12421252 // primary nodes array in the function group
12431253 arr , ok := fgroup ["Nodes" ].(nodes.Array )
@@ -1247,8 +1257,10 @@ func (op opMergeGroups) checkFuncGroup(st *State, fgroup nodes.Object) (bool, er
12471257 modified := false
12481258 for i := 0 ; i < len (arr ); i ++ {
12491259 v := arr [i ]
1260+ // Since we will run this for every group, let's clean a group
1261+ // array from nils here. It could be a separate transform, but
1262+ // it may affect performance, effectively running all checks twice.
12501263 if v == nil {
1251- // remove nil elements
12521264 if ! modified {
12531265 arr = arr .CloneList ()
12541266 modified = true
0 commit comments