Exemple #1
0
  /**
   * Gathers all declarations (functions and static variables) used by the given main module.
   *
   * @param main the main module to start from
   * @return list of all declarations that the main module uses
   */
  public static List<StaticDecl> usedDecls(final MainModule main) {
    final List<StaticDecl> scopes = new ArrayList<>();
    final IdentityHashMap<Scope, Object> map = new IdentityHashMap<>();
    main.visit(
        new ASTVisitor() {
          @Override
          public boolean staticVar(final StaticVar var) {
            if (map.put(var, var) == null) {
              var.visit(this);
              scopes.add(var);
            }
            return true;
          }

          @Override
          public boolean staticFuncCall(final StaticFuncCall call) {
            final StaticFunc f = call.func();
            if (map.put(f, f) == null) {
              f.visit(this);
              scopes.add(f);
            }
            return true;
          }

          @Override
          public boolean inlineFunc(final Scope sub) {
            if (map.put(sub, sub) == null) sub.visit(this);
            return true;
          }

          @Override
          public boolean funcItem(final FuncItem func) {
            if (map.put(func, func) == null) func.visit(this);
            return true;
          }
        });
    return scopes;
  }
Exemple #2
0
 /**
  * Compiles all necessary parts of this query.
  *
  * @param qc query context
  * @param root root expression
  * @throws QueryException compilation errors
  */
 public static void compile(final QueryContext qc, final MainModule root) throws QueryException {
   if (!root.compiled()) new QueryCompiler(qc, root).compile();
 }