(Tree ast)
| 264 | } |
| 265 | |
| 266 | Tree expandMacro(Tree ast) throws ParserException { |
| 267 | LOG.debug("Original macro AST:\n" + ast.toStringTree() + "\n"); |
| 268 | |
| 269 | // first insert the import files |
| 270 | while (expandImport(ast)) |
| 271 | ; |
| 272 | |
| 273 | LOG.debug("macro AST after import:\n" + ast.toStringTree() + "\n"); |
| 274 | |
| 275 | List<CommonTree> macroNodes = new ArrayList<CommonTree>(); |
| 276 | List<CommonTree> inlineNodes = new ArrayList<CommonTree>(); |
| 277 | |
| 278 | // find all macro def/inline nodes |
| 279 | traverse(ast, macroNodes, inlineNodes); |
| 280 | |
| 281 | Map<String, PigMacro> seen = new HashMap<String, PigMacro>(); |
| 282 | List<PigMacro> macroDefs = new ArrayList<PigMacro>(); |
| 283 | |
| 284 | // gether all the def nodes |
| 285 | for (CommonTree t : macroNodes) { |
| 286 | macroDefs.add(makeMacroDef(t, seen)); |
| 287 | } |
| 288 | |
| 289 | // inline macros |
| 290 | inlineMacro(inlineNodes, macroDefs); |
| 291 | |
| 292 | LOG.debug("Resulting macro AST:\n" + ast.toStringTree() + "\n"); |
| 293 | |
| 294 | return ast; |
| 295 | } |
| 296 | |
| 297 | private void inlineMacro(List<CommonTree> inlineNodes, |
| 298 | List<PigMacro> macroDefs) throws ParserException { |
no test coverage detected