| 119 | } |
| 120 | |
| 121 | func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast.Node) { |
| 122 | // convert typed nil into untyped nil |
| 123 | if v := reflect.ValueOf(n); v.Kind() == reflect.Ptr && v.IsNil() { |
| 124 | n = nil |
| 125 | } |
| 126 | |
| 127 | // avoid heap-allocating a new cursor for each apply call; reuse a.cursor instead |
| 128 | saved := a.cursor |
| 129 | a.cursor.parent = parent |
| 130 | a.cursor.name = name |
| 131 | a.cursor.iter = iter |
| 132 | a.cursor.node = n |
| 133 | |
| 134 | if a.pre != nil && !a.pre(&a.cursor) { |
| 135 | a.cursor = saved |
| 136 | return |
| 137 | } |
| 138 | |
| 139 | // walk children |
| 140 | // (the order of the cases matches the order of the corresponding node types in go/ast) |
| 141 | switch n := n.(type) { |
| 142 | case nil: |
| 143 | // nothing to do |
| 144 | |
| 145 | case *ast.AlterTableSetSchemaStmt: |
| 146 | a.apply(n, "Table", nil, n.Table) |
| 147 | |
| 148 | case *ast.AlterTypeAddValueStmt: |
| 149 | a.apply(n, "Type", nil, n.Type) |
| 150 | |
| 151 | case *ast.AlterTypeRenameValueStmt: |
| 152 | a.apply(n, "Type", nil, n.Type) |
| 153 | |
| 154 | case *ast.CommentOnColumnStmt: |
| 155 | a.apply(n, "Table", nil, n.Table) |
| 156 | a.apply(n, "Col", nil, n.Col) |
| 157 | |
| 158 | case *ast.CommentOnSchemaStmt: |
| 159 | a.apply(n, "Schema", nil, n.Schema) |
| 160 | |
| 161 | case *ast.CommentOnTableStmt: |
| 162 | a.apply(n, "Table", nil, n.Table) |
| 163 | |
| 164 | case *ast.CommentOnTypeStmt: |
| 165 | a.apply(n, "Type", nil, n.Type) |
| 166 | |
| 167 | case *ast.CommentOnViewStmt: |
| 168 | a.apply(n, "View", nil, n.View) |
| 169 | |
| 170 | case *ast.CreateTableStmt: |
| 171 | a.apply(n, "Name", nil, n.Name) |
| 172 | |
| 173 | case *ast.DropFunctionStmt: |
| 174 | // pass |
| 175 | |
| 176 | case *ast.DropSchemaStmt: |
| 177 | // pass |
| 178 | |