Flattens nested path expressions. @param cc compilation context @return original or optimized expression
(final CompileContext cc)
| 265 | * @return original or optimized expression |
| 266 | */ |
| 267 | private Expr flatten(final CompileContext cc) { |
| 268 | // new list with steps |
| 269 | boolean changed = false; |
| 270 | final ExprList tmp = new ExprList(steps.length); |
| 271 | |
| 272 | // flatten nested path |
| 273 | Expr rt = root; |
| 274 | if(rt instanceof final Path path) { |
| 275 | tmp.add(path.steps); |
| 276 | rt = path.root; |
| 277 | cc.info(QueryText.OPTFLAT_X_X, (Supplier<?>) path::description, path); |
| 278 | changed = true; |
| 279 | } |
| 280 | |
| 281 | // add steps of input array |
| 282 | for(final Expr step : steps) { |
| 283 | Expr expr = step; |
| 284 | if(expr instanceof final Path path) { |
| 285 | // rewrite nested path to axis steps |
| 286 | if(path.root != null && !(path.root instanceof ContextValue)) tmp.add(path.root); |
| 287 | final int pl = path.steps.length - 1; |
| 288 | for(int i = 0; i < pl; i++) tmp.add(path.steps[i]); |
| 289 | expr = path.steps[pl]; |
| 290 | cc.info(QueryText.OPTFLAT_X_X, (Supplier<?>) path::description, path); |
| 291 | changed = true; |
| 292 | } |
| 293 | tmp.add(expr); |
| 294 | } |
| 295 | return changed ? get(info, rt, tmp.finish()) : this; |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Simplifies the path expression. |