Java 类com.sun.codemodel.JLabel 实例源码

项目:kola    文件:StatementScope.java   
@Override
public JLabel resolveLabel(String name) {
    JLabel l = labels.get(name);
    if (l != null) {
        return l;
    } else {
        return parent().resolveLabel(name);
    }
}
项目:kola    文件:ResolutionContext.java   
void addLabel(String name, JLabel label) {
    if (current instanceof Scope.Labelled) {
        Scope.Labelled labelledScope = (Scope.Labelled) current;
        labelledScope.addLabel(name, label);
    } else {
        Logger.error("Cannot add label (" + name + ") to a Scope (" + current.getClass().getName() + ") that doesn't allow labels!");
        throw new RuntimeException("Invalid Scope for operation!");
    }
}
项目:kola    文件:ResolutionContext.java   
Optional<JLabel> resolveLabel(String id) {
    JLabel l = current.resolveLabel(id);
    if (l == null) {
        return Optional.absent();
    } else {
        return Optional.of(l);
    }
}
项目:kola    文件:StatementAdapter.java   
@Override
public void caseALabeledStatement(ALabeledStatement node) {
    String labelName = node.getIdentifier().getText();
    JLabel label = parent.createLabel(labelName);
    context.pushStatementScope();
    try {
        context.addLabel(labelName, label);
        StatementAdapter sa = new StatementAdapter(parent, context);
        node.getStatement().apply(sa);
    } finally {
        context.popScope();
    }
}
项目:kola    文件:StatementAdapter.java   
@Override
public void caseABreakStatement(ABreakStatement node) {
    if (node.getIdentifier() != null) {
        String id = node.getIdentifier().getText();
        Optional<JLabel> olabel = context.resolveLabel(id);
        if (olabel.isPresent()) {
            parent._break(olabel.get());
        } else {
            Logger.error(context.getFile(), node.getIdentifier(), "Couldn't find label for id. Skipping break target.");
            parent._break();
        }
    } else {
        parent._break();
    }
}
项目:kola    文件:StatementAdapter.java   
@Override
public void caseAContinueStatement(AContinueStatement node) {
    if (node.getIdentifier() != null) {
        String id = node.getIdentifier().getText();
        Optional<JLabel> olabel = context.resolveLabel(id);
        if (olabel.isPresent()) {
            parent._continue(olabel.get());
        } else {
            Logger.error(context.getFile(), node.getIdentifier(), "Couldn't find label for id. Skipping continue target.");
            parent._continue();
        }
    } else {
        parent._continue();
    }
}
项目:QDrill    文件:EvaluationVisitor.java   
private HoldingContainer visitBooleanAnd(BooleanOperator op,
    ClassGenerator<?> generator) {

  HoldingContainer out = generator.declare(op.getMajorType());

  JLabel label = generator.getEvalBlockLabel("AndOP");
  JBlock eval = generator.getEvalBlock().block();  // enter into nested block
  generator.nestEvalBlock(eval);

  HoldingContainer arg = null;

  JExpression e = null;

  //  value of boolean "and" when one side is null
  //    p       q     p and q
  //    true    null     null
  //    false   null     false
  //    null    true     null
  //    null    false    false
  //    null    null     null
  for (int i = 0; i < op.args.size(); i++) {
    arg = op.args.get(i).accept(this, generator);

    JBlock earlyExit = null;
    if (arg.isOptional()) {
      earlyExit = eval._if(arg.getIsSet().eq(JExpr.lit(1)).cand(arg.getValue().ne(JExpr.lit(1))))._then();
      if (e == null) {
        e = arg.getIsSet();
      } else {
        e = e.mul(arg.getIsSet());
      }
    } else {
      earlyExit = eval._if(arg.getValue().ne(JExpr.lit(1)))._then();
    }

    if (out.isOptional()) {
      earlyExit.assign(out.getIsSet(), JExpr.lit(1));
    }

    earlyExit.assign(out.getValue(),  JExpr.lit(0));
    earlyExit._break(label);
  }

  if (out.isOptional()) {
    assert (e != null);

    JConditional notSetJC = eval._if(e.eq(JExpr.lit(0)));
    notSetJC._then().assign(out.getIsSet(), JExpr.lit(0));

    JBlock setBlock = notSetJC._else().block();
    setBlock.assign(out.getIsSet(), JExpr.lit(1));
    setBlock.assign(out.getValue(), JExpr.lit(1));
  } else {
    assert (e == null);
    eval.assign(out.getValue(), JExpr.lit(1)) ;
  }

  generator.unNestEvalBlock();     // exit from nested block

  return out;
}
项目:QDrill    文件:EvaluationVisitor.java   
private HoldingContainer visitBooleanOr(BooleanOperator op,
    ClassGenerator<?> generator) {

  HoldingContainer out = generator.declare(op.getMajorType());

  JLabel label = generator.getEvalBlockLabel("OrOP");
  JBlock eval = generator.getEvalBlock().block();
  generator.nestEvalBlock(eval);   // enter into nested block.

  HoldingContainer arg = null;

  JExpression e = null;

  //  value of boolean "or" when one side is null
  //    p       q       p and q
  //    true    null     true
  //    false   null     null
  //    null    true     true
  //    null    false    null
  //    null    null     null

  for (int i = 0; i < op.args.size(); i++) {
    arg = op.args.get(i).accept(this, generator);

    JBlock earlyExit = null;
    if (arg.isOptional()) {
      earlyExit = eval._if(arg.getIsSet().eq(JExpr.lit(1)).cand(arg.getValue().eq(JExpr.lit(1))))._then();
      if (e == null) {
        e = arg.getIsSet();
      } else {
        e = e.mul(arg.getIsSet());
      }
    } else {
      earlyExit = eval._if(arg.getValue().eq(JExpr.lit(1)))._then();
    }

    if (out.isOptional()) {
      earlyExit.assign(out.getIsSet(), JExpr.lit(1));
    }

    earlyExit.assign(out.getValue(),  JExpr.lit(1));
    earlyExit._break(label);
  }

  if (out.isOptional()) {
    assert (e != null);

    JConditional notSetJC = eval._if(e.eq(JExpr.lit(0)));
    notSetJC._then().assign(out.getIsSet(), JExpr.lit(0));

    JBlock setBlock = notSetJC._else().block();
    setBlock.assign(out.getIsSet(), JExpr.lit(1));
    setBlock.assign(out.getValue(), JExpr.lit(0));
  } else {
    assert (e == null);
    eval.assign(out.getValue(), JExpr.lit(0)) ;
  }

  generator.unNestEvalBlock();   // exit from nested block.

  return out;
}
项目:QDrill    文件:ClassGenerator.java   
public JLabel getEvalBlockLabel (String prefix) {
  return getEvalBlock().label(prefix + labelIndex ++);
}
项目:dremio-oss    文件:EvaluationVisitor.java   
private HoldingContainer visitBooleanAnd(BooleanOperator op,
    ClassGenerator<?> generator) {

  HoldingContainer out = generator.declare(op.getCompleteType());

  JLabel label = generator.getEvalBlockLabel("AndOP");
  JBlock eval = generator.createInnerEvalBlock();
  generator.nestEvalBlock(eval);  // enter into nested block

  HoldingContainer arg = null;

  JExpression e = null;

  //  value of boolean "and" when one side is null
  //    p       q     p and q
  //    true    null     null
  //    false   null     false
  //    null    true     null
  //    null    false    false
  //    null    null     null
  for (int i = 0; i < op.args.size(); i++) {
    arg = op.args.get(i).accept(this, generator);

    JBlock earlyExit = null;
      earlyExit = eval._if(arg.getIsSet().eq(JExpr.lit(1)).cand(arg.getValue().ne(JExpr.lit(1))))._then();
      if (e == null) {
        e = arg.getIsSet();
      } else {
        e = e.mul(arg.getIsSet());
      }
    earlyExit.assign(out.getIsSet(), JExpr.lit(1));

    earlyExit.assign(out.getValue(),  JExpr.lit(0));
    earlyExit._break(label);
  }

  assert (e != null);

  JConditional notSetJC = eval._if(e.eq(JExpr.lit(0)));
  notSetJC._then().assign(out.getIsSet(), JExpr.lit(0));

  JBlock setBlock = notSetJC._else().block();
  setBlock.assign(out.getIsSet(), JExpr.lit(1));
  setBlock.assign(out.getValue(), JExpr.lit(1));

  generator.unNestEvalBlock();     // exit from nested block

  return out;
}
项目:dremio-oss    文件:EvaluationVisitor.java   
private HoldingContainer visitBooleanOr(BooleanOperator op,
    ClassGenerator<?> generator) {

  HoldingContainer out = generator.declare(op.getCompleteType());

  JLabel label = generator.getEvalBlockLabel("OrOP");
  JBlock eval = generator.createInnerEvalBlock();
  generator.nestEvalBlock(eval);   // enter into nested block.

  HoldingContainer arg = null;

  JExpression e = null;

  //  value of boolean "or" when one side is null
  //    p       q       p and q
  //    true    null     true
  //    false   null     null
  //    null    true     true
  //    null    false    null
  //    null    null     null

  for (int i = 0; i < op.args.size(); i++) {
    arg = op.args.get(i).accept(this, generator);

    JBlock earlyExit = eval._if(arg.getIsSet().eq(JExpr.lit(1)).cand(arg.getValue().eq(JExpr.lit(1))))._then();
    if (e == null) {
      e = arg.getIsSet();
    } else {
      e = e.mul(arg.getIsSet());
    }
    earlyExit.assign(out.getIsSet(), JExpr.lit(1));
    earlyExit.assign(out.getValue(),  JExpr.lit(1));
    earlyExit._break(label);
  }

  assert (e != null);

  JConditional notSetJC = eval._if(e.eq(JExpr.lit(0)));
  notSetJC._then().assign(out.getIsSet(), JExpr.lit(0));

  JBlock setBlock = notSetJC._else().block();
  setBlock.assign(out.getIsSet(), JExpr.lit(1));
  setBlock.assign(out.getValue(), JExpr.lit(0));

  generator.unNestEvalBlock();   // exit from nested block.

  return out;
}
项目:dremio-oss    文件:ClassGenerator.java   
public JLabel getEvalBlockLabel (String prefix) {
  return getEvalBlock().label(prefix + labelIndex ++);
}
项目:drill    文件:EvaluationVisitor.java   
private HoldingContainer visitBooleanAnd(BooleanOperator op,
    ClassGenerator<?> generator) {

  HoldingContainer out = generator.declare(op.getMajorType());

  JLabel label = generator.getEvalBlockLabel("AndOP");
  JBlock eval = generator.createInnerEvalBlock();
  generator.nestEvalBlock(eval);  // enter into nested block

  HoldingContainer arg = null;

  JExpression e = null;

  //  value of boolean "and" when one side is null
  //    p       q     p and q
  //    true    null     null
  //    false   null     false
  //    null    true     null
  //    null    false    false
  //    null    null     null
  for (int i = 0; i < op.args.size(); i++) {
    arg = op.args.get(i).accept(this, generator);

    JBlock earlyExit = null;
    if (arg.isOptional()) {
      earlyExit = eval._if(arg.getIsSet().eq(JExpr.lit(1)).cand(arg.getValue().ne(JExpr.lit(1))))._then();
      if (e == null) {
        e = arg.getIsSet();
      } else {
        e = e.mul(arg.getIsSet());
      }
    } else {
      earlyExit = eval._if(arg.getValue().ne(JExpr.lit(1)))._then();
    }

    if (out.isOptional()) {
      earlyExit.assign(out.getIsSet(), JExpr.lit(1));
    }

    earlyExit.assign(out.getValue(),  JExpr.lit(0));
    earlyExit._break(label);
  }

  if (out.isOptional()) {
    assert (e != null);

    JConditional notSetJC = eval._if(e.eq(JExpr.lit(0)));
    notSetJC._then().assign(out.getIsSet(), JExpr.lit(0));

    JBlock setBlock = notSetJC._else().block();
    setBlock.assign(out.getIsSet(), JExpr.lit(1));
    setBlock.assign(out.getValue(), JExpr.lit(1));
  } else {
    assert (e == null);
    eval.assign(out.getValue(), JExpr.lit(1)) ;
  }

  generator.unNestEvalBlock();     // exit from nested block

  return out;
}
项目:drill    文件:EvaluationVisitor.java   
private HoldingContainer visitBooleanOr(BooleanOperator op,
    ClassGenerator<?> generator) {

  HoldingContainer out = generator.declare(op.getMajorType());

  JLabel label = generator.getEvalBlockLabel("OrOP");
  JBlock eval = generator.createInnerEvalBlock();
  generator.nestEvalBlock(eval);   // enter into nested block.

  HoldingContainer arg = null;

  JExpression e = null;

  //  value of boolean "or" when one side is null
  //    p       q       p and q
  //    true    null     true
  //    false   null     null
  //    null    true     true
  //    null    false    null
  //    null    null     null

  for (int i = 0; i < op.args.size(); i++) {
    arg = op.args.get(i).accept(this, generator);

    JBlock earlyExit = null;
    if (arg.isOptional()) {
      earlyExit = eval._if(arg.getIsSet().eq(JExpr.lit(1)).cand(arg.getValue().eq(JExpr.lit(1))))._then();
      if (e == null) {
        e = arg.getIsSet();
      } else {
        e = e.mul(arg.getIsSet());
      }
    } else {
      earlyExit = eval._if(arg.getValue().eq(JExpr.lit(1)))._then();
    }

    if (out.isOptional()) {
      earlyExit.assign(out.getIsSet(), JExpr.lit(1));
    }

    earlyExit.assign(out.getValue(),  JExpr.lit(1));
    earlyExit._break(label);
  }

  if (out.isOptional()) {
    assert (e != null);

    JConditional notSetJC = eval._if(e.eq(JExpr.lit(0)));
    notSetJC._then().assign(out.getIsSet(), JExpr.lit(0));

    JBlock setBlock = notSetJC._else().block();
    setBlock.assign(out.getIsSet(), JExpr.lit(1));
    setBlock.assign(out.getValue(), JExpr.lit(0));
  } else {
    assert (e == null);
    eval.assign(out.getValue(), JExpr.lit(0)) ;
  }

  generator.unNestEvalBlock();   // exit from nested block.

  return out;
}
项目:drill    文件:ClassGenerator.java   
public JLabel getEvalBlockLabel (String prefix) {
  return getEvalBlock().label(prefix + labelIndex++);
}
项目:kola    文件:JBlockParent.java   
@Override
public JLabel createLabel(String name) {
    return block.label(name);
}
项目:kola    文件:JBlockParent.java   
@Override
public void _break(JLabel label) {
    block._break(label);
}
项目:kola    文件:JBlockParent.java   
@Override
public void _continue(JLabel label) {
    block._continue(label);
}
项目:kola    文件:StatementScope.java   
@Override
public void addLabel(String name, JLabel label) {
    labels.put(name, label);
}
项目:kola    文件:GlobalScope.java   
@Override
public JLabel resolveLabel(String name) {
    return null;
}
项目:kola    文件:AnonClassScope.java   
@Override
public JLabel resolveLabel(String name) {
    return null;
}
项目:kola    文件:PackageScope.java   
@Override
public JLabel resolveLabel(String name) {
    return null;
}
项目:kola    文件:FileScope.java   
@Override
public JLabel resolveLabel(String name) {
    return null;
}
项目:kola    文件:TypeScope.java   
@Override
public JLabel resolveLabel(String name) {
    return null;
}
项目:kola    文件:MethodScope.java   
@Override
public JLabel resolveLabel(String name) {
    return null; // no point in resolving labels higher than one StatementScope
}
项目:kola    文件:Scope.java   
public abstract JLabel resolveLabel(String name);
项目:kola    文件:Scope.java   
public void addLabel(String name, JLabel label);
项目:kola    文件:StatementAdapter.java   
public JLabel createLabel(String name);
项目:kola    文件:StatementAdapter.java   
public void _break(JLabel label);
项目:kola    文件:StatementAdapter.java   
public void _continue(JLabel label);