本文整理汇总了Java中edu.mit.csail.sdg.alloy4compiler.ast.ExprBinary类的典型用法代码示例。如果您正苦于以下问题:Java ExprBinary类的具体用法?Java ExprBinary怎么用?Java ExprBinary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExprBinary类属于edu.mit.csail.sdg.alloy4compiler.ast包,在下文中一共展示了ExprBinary类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isIn
import edu.mit.csail.sdg.alloy4compiler.ast.ExprBinary; //导入依赖的package包/类
/** Helper method that evaluates the formula "a in b" */
private boolean isIn(SimTupleset a, Expr b) throws Err {
b = b.deNOP();
if (b instanceof ExprBinary && b.mult!=0 && ((ExprBinary)b).op.isArrow) {
// Handles possible "binary" or higher-arity multiplicity
return isInBinary(a, (ExprBinary)b);
}
if (b instanceof ExprUnary) {
// Handles possible "unary" multiplicity
ExprUnary y = (ExprUnary)b;
if (y.op==ExprUnary.Op.EXACTLYOF) { b = y.sub.deNOP(); return a.equals(cset(b)); }
else if (y.op==ExprUnary.Op.ONEOF) { b = y.sub.deNOP(); if (!(a.longsize()==1)) return false; }
else if (y.op==ExprUnary.Op.LONEOF) { b = y.sub.deNOP(); if (!(a.longsize()<=1)) return false; }
else if (y.op==ExprUnary.Op.SOMEOF) { b = y.sub.deNOP(); if (!(a.longsize()>=1)) return false; }
else if (y.op!=ExprUnary.Op.SETOF) { b = y.sub.deNOP(); }
}
for(SimTuple t:a) if (!isIn(t, b)) return false;
return true;
}
示例2: visit
import edu.mit.csail.sdg.alloy4compiler.ast.ExprBinary; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public Expr visit(ExprBinary x) throws Err {
Expr left = visitThis(x.left);
Expr right = visitThis(x.right);
if (x.op==ExprBinary.Op.JOIN) {
// If it's a macro invocation, instantiate it
if (right instanceof Macro) return ((Macro)right).addArg(left).instantiate(this, warns);
// check to see if it is the special builtin function "Int[]"
if (left.type().is_int() && right.isSame(Sig.SIGINT)) return left; //[AM] .cast2sigint();
// otherwise, process as regular join or as method call
left = left.typecheck_as_set();
if (!left.errors.isEmpty() || !(right instanceof ExprChoice)) return x.op.make(x.pos, x.closingBracket, left, right);
return process(x.pos, x.closingBracket, right.pos, ((ExprChoice)right).choices, ((ExprChoice)right).reasons, left);
}
return x.op.make(x.pos, x.closingBracket, left, right);
}
示例3: a2k
import edu.mit.csail.sdg.alloy4compiler.ast.ExprBinary; //导入依赖的package包/类
/** Returns the corresponding Kodkod expression for the given expression, or null if it is not associated with anything. */
Expression a2k(Expr expr) throws ErrorFatal {
while(expr instanceof ExprUnary) {
if (((ExprUnary)expr).op==ExprUnary.Op.NOOP) { expr = ((ExprUnary)expr).sub; continue; }
if (((ExprUnary)expr).op==ExprUnary.Op.EXACTLYOF) { expr = ((ExprUnary)expr).sub; continue; }
break;
}
if (expr instanceof ExprConstant && ((ExprConstant)expr).op==ExprConstant.Op.EMPTYNESS) return Expression.NONE;
if (expr instanceof ExprConstant && ((ExprConstant)expr).op==ExprConstant.Op.STRING) return s2k.get(((ExprConstant)expr).string);
if (expr instanceof Sig || expr instanceof Field || expr instanceof ExprVar) return a2k.get(expr);
if (expr instanceof ExprBinary) {
Expr a=((ExprBinary)expr).left, b=((ExprBinary)expr).right;
switch(((ExprBinary)expr).op) {
case ARROW: return a2k(a).product(a2k(b));
case PLUS: return a2k(a).union(a2k(b));
case MINUS: return a2k(a).difference(a2k(b));
//TODO: IPLUS, IMINUS???
}
}
return null; // Current only UNION, PRODUCT, and DIFFERENCE of Sigs and Fields and ExprConstant.EMPTYNESS are allowed in a defined field's definition.
}
示例4: process
import edu.mit.csail.sdg.alloy4compiler.ast.ExprBinary; //导入依赖的package包/类
private Expr process(Pos pos, Pos closingBracket, Pos rightPos, List<Expr> choices, List<String> oldReasons, Expr arg) {
TempList<Expr> list = new TempList<Expr>(choices.size());
TempList<String> reasons = new TempList<String>(choices.size());
for(int i=0; i<choices.size(); i++) {
Expr x=choices.get(i), y=x;
while(true) {
if (y instanceof ExprUnary && ((ExprUnary)y).op==ExprUnary.Op.NOOP) y=((ExprUnary)y).sub;
else if (y instanceof ExprChoice && ((ExprChoice)y).choices.size()==1) y=((ExprChoice)y).choices.get(0);
else break;
}
if (y instanceof ExprBadCall) {
ExprBadCall bc = (ExprBadCall)y;
if (bc.args.size() < bc.fun.count()) {
ConstList<Expr> newargs = Util.append(bc.args, arg);
if (applicable(bc.fun, newargs))
y=ExprCall.make(bc.pos, bc.closingBracket, bc.fun, newargs, bc.extraWeight);
else
y=ExprBadCall.make(bc.pos, bc.closingBracket, bc.fun, newargs, bc.extraWeight);
} else {
y=ExprBinary.Op.JOIN.make(pos, closingBracket, arg, y);
}
} else {
y=ExprBinary.Op.JOIN.make(pos, closingBracket, arg, x);
}
list.add(y);
reasons.add(oldReasons.get(i));
}
return ExprChoice.make(rightPos, list.makeConst(), reasons.makeConst());
}
示例5: sim
import edu.mit.csail.sdg.alloy4compiler.ast.ExprBinary; //导入依赖的package包/类
/** If ex is a simple combination of Relations, then return that combination, else return null. */
private Expression sim(Expr ex) {
while(ex instanceof ExprUnary) {
ExprUnary u = (ExprUnary)ex;
if (u.op!=ExprUnary.Op.NOOP && u.op!=ExprUnary.Op.EXACTLYOF) break;
ex = u.sub;
}
if (ex instanceof ExprBinary) {
ExprBinary b = (ExprBinary)ex;
if (b.op==ExprBinary.Op.ARROW || b.op==ExprBinary.Op.PLUS || b.op==ExprBinary.Op.JOIN) {
Expression left = sim(b.left); if (left==null) return null;
Expression right = sim(b.right); if (right==null) return null;
if (b.op==ExprBinary.Op.ARROW) return left.product(right);
if (b.op==ExprBinary.Op.PLUS) return left.union(right); else return left.join(right);
}
}
if (ex instanceof ExprConstant) {
switch(((ExprConstant)ex).op) {
case EMPTYNESS: return Expression.NONE;
}
}
if (ex==Sig.NONE) return Expression.NONE;
if (ex==Sig.SIGINT) return Expression.INTS;
if (ex instanceof Sig) return sol.a2k((Sig)ex);
if (ex instanceof Field) return sol.a2k((Field)ex);
return null;
}
示例6: visit
import edu.mit.csail.sdg.alloy4compiler.ast.ExprBinary; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public Expr visit(ExprBinary x) throws Err {
if (x.op == ExprBinary.Op.AND) {
Expr a = visitThis(x.left);
Expr b = visitThis(x.right);
return a.and(b);
}
return x;
}
示例7: isIn
import edu.mit.csail.sdg.alloy4compiler.ast.ExprBinary; //导入依赖的package包/类
/** Helper method that translates the formula "a in b" into a Kodkod formula. */
private Formula isIn(Expression a, Expr right) throws Err {
Expression b;
if (right instanceof ExprBinary && right.mult!=0 && ((ExprBinary)right).op.isArrow) {
// Handles possible "binary" or higher-arity multiplicity
return isInBinary(a, (ExprBinary)right);
}
switch(right.mult()) {
case EXACTLYOF: b=cset(right); return a.eq(b);
case ONEOF: b=cset(right); return a.one().and(a.in(b));
case LONEOF: b=cset(right); return a.lone().and(a.in(b));
case SOMEOF: b=cset(right); return a.some().and(a.in(b));
default: b=cset(right); return a.in(b);
}
}