Exemple #1
0
 /**
  * Gibt das uebergeordnete CFXD Tag Element zurueck, falls dies nicht existiert wird null
  * zurueckgegeben.
  *
  * @param el Element von dem das parent Element zurueckgegeben werden soll.
  * @return uebergeordnete CFXD Tag Element
  */
 public static Tag getParentTag(Tag tag) {
   Statement p = tag.getParent();
   if (p == null) return null;
   p = p.getParent();
   if (p instanceof Tag) return (Tag) p;
   return null;
 }
Exemple #2
0
 public static Page getAncestorPage(Statement stat, Page defaultValue) {
   Statement parent = stat;
   while (true) {
     parent = parent.getParent();
     if (parent == null) {
       return defaultValue;
     }
     if (parent instanceof Page) return (Page) parent;
   }
 }
Exemple #3
0
 public static void listAncestor(Statement stat) {
   Statement parent = stat;
   aprint.o(stat);
   while (true) {
     parent = parent.getParent();
     if (parent instanceof Page)
       aprint.o("page-> " + ((Page) parent).getPageSource().getDisplayPath());
     else aprint.o("parent-> " + parent);
     if (parent == null) break;
   }
 }
Exemple #4
0
 public static Page getAncestorPage(Statement stat) throws BytecodeException {
   Statement parent = stat;
   while (true) {
     parent = parent.getParent();
     if (parent == null) {
       throw new BytecodeException("missing parent Statement of Statement", stat.getStart());
       // return null;
     }
     if (parent instanceof Page) return (Page) parent;
   }
 }
Exemple #5
0
 /**
  * Gibt ein uebergeordnetes Tag mit dem uebergebenen Full-Name (Namespace und Name) zurueck, falls
  * ein solches existiert, andernfalls wird null zurueckgegeben.
  *
  * @param el Startelement, von wo aus gesucht werden soll.
  * @param fullName Name des gesuchten Tags.
  * @return uebergeornetes Element oder null.
  */
 public static Tag getAncestorTag(Tag tag, String fullName) {
   Statement parent = tag;
   while (true) {
     parent = parent.getParent();
     if (parent == null) return null;
     if (parent instanceof Tag) {
       tag = (Tag) parent;
       if (tag.getFullname().equalsIgnoreCase(fullName)) return tag;
     }
   }
 }
Exemple #6
0
  public static Statement getAncestorTryStatement(Statement stat) {
    Statement parent = stat;
    while (true) {
      parent = parent.getParent();
      if (parent == null) return null;

      if (parent instanceof TagTry) {
        return parent;
      } else if (parent instanceof TryCatchFinally) {
        return parent;
      }
    }
  }
Exemple #7
0
 public static Tag getAncestorComponent(Statement stat) throws BytecodeException {
   // print.ln("getAncestorPage:"+stat);
   Statement parent = stat;
   while (true) {
     parent = parent.getParent();
     // print.ln(" - "+parent);
     if (parent == null) {
       throw new BytecodeException("missing parent Statement of Statement", stat.getStart());
       // return null;
     }
     if (parent instanceof TagComponent)
       // if(parent instanceof Tag && "component".equals(((Tag)parent).getTagLibTag().getName()))
       return (Tag) parent;
   }
 }
Exemple #8
0
  public static boolean isCFC(Statement s) {
    Statement p;
    while ((p = s.getParent()) != null) {
      s = p;
    }

    return true;
  }
Exemple #9
0
 public static Statement getRoot(Statement stat) {
   while (true) {
     if (isRoot(stat)) {
       return stat;
     }
     stat = stat.getParent();
   }
 }
Exemple #10
0
  private static FlowControl getAncestorFCStatement(
      Statement stat, List<FlowControlFinal> finallyLabels, int flowType, String label) {
    Statement parent = stat;
    FlowControlFinal fcf;
    while (true) {
      parent = parent.getParent();
      if (parent == null) return null;
      if (((flowType == FlowControl.RETRY && parent instanceof FlowControlRetry)
              || (flowType == FlowControl.CONTINUE && parent instanceof FlowControlContinue)
              || (flowType == FlowControl.BREAK && parent instanceof FlowControlBreak))
          && labelMatch((FlowControl) parent, label)) {
        if (parent instanceof ScriptBody) {
          List<FlowControlFinal> _finallyLabels =
              finallyLabels == null ? null : new ArrayList<FlowControlFinal>();

          FlowControl scriptBodyParent =
              getAncestorFCStatement(parent, _finallyLabels, flowType, label);
          if (scriptBodyParent != null) {
            if (finallyLabels != null) {
              Iterator<FlowControlFinal> it = _finallyLabels.iterator();
              while (it.hasNext()) {
                finallyLabels.add(it.next());
              }
            }
            return scriptBodyParent;
          }
          return (FlowControl) parent;
        }
        return (FlowControl) parent;
      }

      // only if not last
      if (finallyLabels != null) {
        fcf = parent.getFlowControlFinal();
        if (fcf != null) {
          finallyLabels.add(fcf);
        }
      }
    }
  }
Exemple #11
0
  public static void dump(Statement s, int level) {

    for (int i = 0; i < level; i++) System.err.print("-");
    aprint.e(s.getClass().getName());

    if (s instanceof HasBody) {
      Body b = ((HasBody) s).getBody();
      if (b != null) {
        Iterator<Statement> it = b.getStatements().iterator();
        while (it.hasNext()) {
          dump(it.next(), level + 1);
        }
      }
    }
  }
Exemple #12
0
  public static void leadFlow(BytecodeContext bc, Statement stat, int flowType, String label)
      throws BytecodeException {
    List<FlowControlFinal> finallyLabels = new ArrayList<FlowControlFinal>();

    FlowControl fc;
    String name;
    if (FlowControl.BREAK == flowType) {
      fc = ASMUtil.getAncestorBreakFCStatement(stat, finallyLabels, label);
      name = "break";
    } else if (FlowControl.CONTINUE == flowType) {
      fc = ASMUtil.getAncestorContinueFCStatement(stat, finallyLabels, label);
      name = "continue";
    } else {
      fc = ASMUtil.getAncestorRetryFCStatement(stat, finallyLabels, label);
      name = "retry";
    }

    if (fc == null)
      throw new BytecodeException(
          name + " must be inside a loop (for,while,do-while,<cfloop>,<cfwhile> ...)",
          stat.getStart());

    GeneratorAdapter adapter = bc.getAdapter();

    Label end;
    if (FlowControl.BREAK == flowType) end = ((FlowControlBreak) fc).getBreakLabel();
    else if (FlowControl.CONTINUE == flowType) end = ((FlowControlContinue) fc).getContinueLabel();
    else end = ((FlowControlRetry) fc).getRetryLabel();

    // first jump to all final labels
    FlowControlFinal[] arr = finallyLabels.toArray(new FlowControlFinal[finallyLabels.size()]);
    if (arr.length > 0) {
      FlowControlFinal fcf;
      for (int i = 0; i < arr.length; i++) {
        fcf = arr[i];

        // first
        if (i == 0) {
          adapter.visitJumpInsn(Opcodes.GOTO, fcf.getFinalEntryLabel());
        }

        // last
        if (arr.length == i + 1) fcf.setAfterFinalGOTOLabel(end);
        else fcf.setAfterFinalGOTOLabel(arr[i + 1].getFinalEntryLabel());
      }

    } else bc.getAdapter().visitJumpInsn(Opcodes.GOTO, end);
  }