Examples of SwitchCase


Examples of com.dragome.compiler.ast.SwitchCase

    switchStmt.getExpression().visit(this);
    println(") {");
    ASTNode node= switchStmt.getFirstChild();
    while (node != null)
    {
      SwitchCase sc= (SwitchCase) node;
      sc.visit(this);
      node= node.getNextSibling();
    }
    indentln("}");
  }
View Full Code Here

Examples of com.dragome.compiler.ast.SwitchCase

    switchStmt.setExpression(header.switchExpression);

    for (int i= 0; i < caseGroups.size(); i++)
    {
      Node scNode= caseGroups.get(i);
      SwitchCase switchCase= new SwitchCase(scNode.getInitialPc());
      switchCase.setExpressions(caseGroupExpressions.get(i));
      switchStmt.appendChild(switchCase);

      graph.rollOut(scNode, switchCase);
    }
View Full Code Here

Examples of com.google.caja.parser.js.SwitchCase

    // Eliminate unnecessary default statements.
    // Having a default statement prevents other optimizations so aggressively
    // optimize them out where possible.
    boolean hasDefault = false;
    for (int i = newChildren.size(); --i >= 1;) {
      SwitchCase cs = (SwitchCase) newChildren.get(i);
      if (!(cs instanceof DefaultCaseStmt)) { continue; }
      Block body = cs.getBody();
      if (body.children().isEmpty()) {
        changed = true;
        newChildren.remove(i);
      } else if (isBlankBreak(body)) {
        if (i != 1 || !exits(((SwitchCase) newChildren.get(i - 1)).getBody())) {
          // Move the break into the preceding case.
          SwitchCase prev = (SwitchCase) newChildren.get(i - 1);
          newChildren.set(i - 1, withBody(prev, combine(prev.getBody(), body)));
          changed = true;
        }
        newChildren.remove(i);
        changed = true;
      } else {
        hasDefault = true;
      }
    }
    // Eliminate unnecessary breaks
    if (!hasDefault) {
      for (int i = newChildren.size(); --i >= 1;) {
        CaseStmt cs = (CaseStmt) newChildren.get(i);
        Block body = cs.getBody();
        if (!isBlankBreak(body)) { continue; }
        if (cs.getCaseValue().simplifyForSideEffect() != null) { continue; }
        if (i != 1) {
          SwitchCase prev = (SwitchCase) newChildren.get(i - 1);
          if (!exits(prev.getBody())) {
            // Move the break into the preceding case.
            newChildren.set(
                i - 1, withBody(prev, combine(prev.getBody(), body)));
          }
        }
        newChildren.remove(i);
        changed = true;
      }
    }
    // Eliminate duplicate cases
    SwitchCase last = null;
    for (int i = 1; i < newChildren.size(); ++i) {
      SwitchCase cs = (SwitchCase) newChildren.get(i);
      if (last != null && !last.getBody().children().isEmpty()
          && ParseTreeNodes.deepEquals(last.getBody(), cs.getBody())) {
        newChildren.set(i - 1, withoutBody(last));
        changed = true;
      }
      last = cs;
    }
    while (newChildren.size() > 1) {
      int lastIndex = newChildren.size() - 1;
      last = (SwitchCase) newChildren.get(lastIndex);

      Block lastBody = last.getBody();
      boolean changedOne = false;
      if (!lastBody.children().isEmpty()) {
        // Eliminate trailing break statement.
        List<? extends Statement> stmts = lastBody.children();
        int n = stmts.size();
        if (n > 0 && isBlankBreak(stmts.get(n - 1))) {
          stmts = stmts.subList(0, n - 1);
          Block newBody = new Block(lastBody.getFilePosition(), stmts);
          newChildren.set(newChildren.size() - 1, withBody(last, newBody));
          changedOne = true;
        }
      } else if (isBlankBreak(lastBody)) {
        //    switch (...) { default: ... case foo: break; }
        // => switch (...) { default: ... case foo: }
        newChildren.set(lastIndex, withoutBody(last));
        changedOne = true;
      } else if (!hasDefault) {
        CaseStmt cs = (CaseStmt) last;  // OK since !hasDefault
        //    switch (...) { ... case 4: case 5: break; }
        // => switch (...) { ... }
        // We can eliminate cases entirely if there is no default since it
        // will not change the set of values that default matches.
        if (null == cs.getCaseValue().simplifyForSideEffect()) {
          newChildren.remove(lastIndex);
          changedOne = true;
        }
      }
      if (changedOne) {
View Full Code Here

Examples of com.google.caja.parser.js.SwitchCase

    // Eliminate unnecessary default statements.
    // Having a default statement prevents other optimizations so aggressively
    // optimize them out where possible.
    boolean hasDefault = false;
    for (int i = newChildren.size(); --i >= 1;) {
      SwitchCase cs = (SwitchCase) newChildren.get(i);
      if (!(cs instanceof DefaultCaseStmt)) { continue; }
      Block body = cs.getBody();
      if (body.children().isEmpty()) {
        changed = true;
        newChildren.remove(i);
      } else if (isBlankBreak(body)) {
        if (i != 1 || !exits(((SwitchCase) newChildren.get(i - 1)).getBody())) {
          // Move the break into the preceding case.
          SwitchCase prev = (SwitchCase) newChildren.get(i - 1);
          newChildren.set(i - 1, withBody(prev, combine(prev.getBody(), body)));
          changed = true;
        }
        newChildren.remove(i);
        changed = true;
      } else {
        hasDefault = true;
      }
    }
    // Eliminate unnecessary breaks
    if (!hasDefault) {
      for (int i = newChildren.size(); --i >= 1;) {
        CaseStmt cs = (CaseStmt) newChildren.get(i);
        Block body = cs.getBody();
        if (!isBlankBreak(body)) { continue; }
        if (cs.getCaseValue().simplifyForSideEffect() != null) { continue; }
        if (i != 1) {
          SwitchCase prev = (SwitchCase) newChildren.get(i - 1);
          if (!exits(prev.getBody())) {
            // Move the break into the preceding case.
            newChildren.set(
                i - 1, withBody(prev, combine(prev.getBody(), body)));
          }
        }
        newChildren.remove(i);
        changed = true;
      }
    }
    // Eliminate duplicate cases
    SwitchCase last = null;
    for (int i = 1; i < newChildren.size(); ++i) {
      SwitchCase cs = (SwitchCase) newChildren.get(i);
      if (last != null && !last.getBody().children().isEmpty()
          && ParseTreeNodes.deepEquals(last.getBody(), cs.getBody())) {
        newChildren.set(i - 1, withoutBody(last));
        changed = true;
      }
      last = cs;
    }
    while (newChildren.size() > 1) {
      int lastIndex = newChildren.size() - 1;
      last = (SwitchCase) newChildren.get(lastIndex);

      Block lastBody = last.getBody();
      boolean changedOne = false;
      if (!lastBody.children().isEmpty()) {
        // Eliminate trailing break statement.
        List<? extends Statement> stmts = lastBody.children();
        int n = stmts.size();
        if (n > 0 && isBlankBreak(stmts.get(n - 1))) {
          stmts = stmts.subList(0, n - 1);
          Block newBody = new Block(lastBody.getFilePosition(), stmts);
          newChildren.set(newChildren.size() - 1, withBody(last, newBody));
          changedOne = true;
        }
      } else if (isBlankBreak(lastBody)) {
        //    switch (...) { default: ... case foo: break; }
        // => switch (...) { default: ... case foo: }
        newChildren.set(lastIndex, withoutBody(last));
        changedOne = true;
      } else if (!hasDefault) {
        CaseStmt cs = (CaseStmt) last;  // OK since !hasDefault
        //    switch (...) { ... case 4: case 5: break; }
        // => switch (...) { ... }
        // We can eliminate cases entirely if there is no default since it
        // will not change the set of values that default matches.
        if (null == cs.getCaseValue().simplifyForSideEffect()) {
          newChildren.remove(lastIndex);
          changedOne = true;
        }
      }
      if (changedOne) {
View Full Code Here

Examples of com.google.dart.engine.ast.SwitchCase

    NodeList<SwitchMember> switchMembers = node.getMembers();
    boolean foundError = false;
    Type firstType = null;
    for (SwitchMember switchMember : switchMembers) {
      if (switchMember instanceof SwitchCase) {
        SwitchCase switchCase = (SwitchCase) switchMember;
        Expression expression = switchCase.getExpression();
        EvaluationResultImpl caseResult = validate(
            expression,
            CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION);
        if (caseResult instanceof ValidResult) {
          reportErrorIfFromDeferredLibrary(
View Full Code Here

Examples of com.google.dart.engine.ast.SwitchCase

    NodeList<SwitchMember> members = node.getMembers();
    for (SwitchMember switchMember : members) {
      if (!(switchMember instanceof SwitchCase)) {
        continue;
      }
      SwitchCase switchCase = (SwitchCase) switchMember;
      // prepare 'case' type
      Expression caseExpression = switchCase.getExpression();
      Type caseType = getStaticType(caseExpression);
      // check types
      if (expressionType.isAssignableTo(caseType)) {
        return false;
      }
View Full Code Here

Examples of org.apache.synapse.config.xml.SwitchCase

        // set xpath condition to select symbol
        SynapseXPath xpath = new SynapseXPath("//wsx:symbol");
        xpath.addNamespace("wsx", "http://www.webserviceX.NET/");
        switchMediator.setSource(xpath);
        SwitchCase caseOne = new SwitchCase();
        caseOne.setRegex(Pattern.compile("IBM"));
        AnonymousListMediator mediatorOne = new AnonymousListMediator();
        mediatorOne.addAll(Arrays.asList(new Mediator[] {ibmMediator}));
        caseOne.setCaseMediator(mediatorOne);
        SwitchCase caseTwo = new SwitchCase();
        caseTwo.setRegex(Pattern.compile("MSFT"));
        AnonymousListMediator mediatorTwo = new AnonymousListMediator();
        mediatorTwo.addAll(Arrays.asList(new Mediator[] {msftMediator}));
        caseTwo.setCaseMediator(mediatorTwo);

        SwitchCase caseDefault = new SwitchCase();
        AnonymousListMediator mediatorDefault = new AnonymousListMediator();
        mediatorDefault.addAll(Arrays.asList(new Mediator[] {defaultMediator}));
        caseDefault.setCaseMediator(mediatorDefault);
        // set ibm mediator to be called for IBM, msft for MSFT and default for others..
        switchMediator.addCase(caseOne);
        switchMediator.addCase(caseTwo);
        switchMediator.setDefaultCase(caseDefault);      
    }
View Full Code Here

Examples of org.apache.synapse.config.xml.SwitchCase

                return defaultCase.mediate(synCtx);

            } else {
                for (Iterator iter = cases.iterator(); iter.hasNext();) {
                    SwitchCase swCase = (SwitchCase) iter.next();

                    if (swCase != null) {
                        if (swCase.matches(sourceText)) {
                            if (traceOrDebugOn) {
                                traceOrDebug(traceOn, "Matching case found : " + swCase.getRegex());
                            }
                            return swCase.mediate(synCtx);
                        }
                    }
                }

                if (defaultCase != null) {
View Full Code Here

Examples of org.apache.synapse.config.xml.SwitchCase

                trace.trace("Start Case mediator list");
            }
            if (sourceText != null) {
                Iterator iter = cases.iterator();
                while (iter.hasNext()) {
                    SwitchCase swCase = (SwitchCase) iter.next();
                    if (swCase != null) {
                        if (swCase.matches(sourceText)) {
                            if (shouldTrace) {
                                trace.trace("Executing case for : " + swCase.getRegex());
                            }
                            return swCase.mediate(synCtx);
                        }
                    }
                }
                if (shouldTrace) {
                    trace.trace("End Case mediator list");
View Full Code Here

Examples of org.apache.synapse.config.xml.SwitchCase

                return defaultCase.mediate(synCtx);

            } else {
                for (Iterator iter = cases.iterator(); iter.hasNext();) {
                    SwitchCase swCase = (SwitchCase) iter.next();

                    if (swCase != null) {
                        if (swCase.matches(sourceText)) {
                            if (traceOrDebugOn) {
                                traceOrDebug(traceOn, "Matching case found : " + swCase.getRegex());
                            }
                            return swCase.mediate(synCtx);
                        }
                    }
                }

                if (defaultCase != null) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.