本文整理汇总了Java中edu.mit.csail.sdg.alloy4compiler.ast.Sig类的典型用法代码示例。如果您正苦于以下问题:Java Sig类的具体用法?Java Sig怎么用?Java Sig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Sig类属于edu.mit.csail.sdg.alloy4compiler.ast包,在下文中一共展示了Sig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createEReferencesFromSigs
import edu.mit.csail.sdg.alloy4compiler.ast.Sig; //导入依赖的package包/类
private void createEReferencesFromSigs() throws TraceException {
for (Sig sig : solution.getAllReachableSigs()) {
for (Field field : sig.getFields()) {
final String relName = field.label;
SigTrace sigTrace = TraceManager.get().getSigTraceByType(sig.label.replace("this/", ""));
RelationTrace relTrace =
TraceManager.get().getRelationTrace2(sigTrace.getClassName(), relName);
if (relTrace != null) {
String refName = relTrace.getReferenceName();
for (A4Tuple a4Tuple : solution.eval(field)) {
String fromAtom = a4Tuple.atom(0);
String toAtom = a4Tuple.atom(1);
createEReferenceByAtoms(refName, fromAtom, toAtom);
}
} else {
closeWizard();
throw new TraceException("No trace has been found for the relation: " + relName);
}
}
}
}
示例2: initSigBounds
import edu.mit.csail.sdg.alloy4compiler.ast.Sig; //导入依赖的package包/类
private void initSigBounds() {
for (Sig sig : sigs) {
String sigName = sig.label.replace("this/", "");
int lower = 0, upper = DEFAULT_UPPER;
if (sig.isOne != null) {
lower = upper = 1;
} else if (sig.isLone != null) {
lower = 0;
upper = 1;
} else if (sig.isSome != null) {
lower = 1;
upper = DEFAULT_UPPER;
}
EClass sigClass = EcoreUtilities.findEClass(modelRoot, sigName);
if (sigClass != null && !sigClass.isAbstract()) {
BoundItem item = new BoundItem(sigName, lower, upper);
item.setEClass(sigClass);
sig2item.put(sigName, item);
traceCache.put(sigClass.getName(), sigName);
}
}
}
示例3: setStatuofSig
import edu.mit.csail.sdg.alloy4compiler.ast.Sig; //导入依赖的package包/类
private void setStatuofSig(final Sig sig, final SigType sigType) {
if (sig.isAbstract != null) {
sigType.setAbstract("yes");
}
if (sig.isEnum != null) {
sigType.setEnum("yes");
}
if (sig.isLone != null) {
sigType.setLone("yes");
}
if (sig.isMeta != null) {
sigType.setMeta("yes");
}
if (sig.isOne != null) {
sigType.setOne("yes");
}
if (sig.isPrivate != null) {
sigType.setPrivate("yes");
}
if (sig.isSome != null) {
sigType.setSome("yes");
}
}
示例4: sigMETA
import edu.mit.csail.sdg.alloy4compiler.ast.Sig; //导入依赖的package包/类
/** Returns the AlloyType corresponding to the given sig; create an AlloyType for it if none existed before. */
private AlloyType sigMETA(PrimSig s) throws Err {
if (s==Sig.NONE) throw new ErrorFatal("Unexpected sig \"none\" encountered.");
AlloyType type = sig2type.get(s);
if (type != null) return type;
if (s==Sig.UNIV) type=AlloyType.UNIV;
else if (s==Sig.SIGINT) type=AlloyType.INT;
else if (s==Sig.SEQIDX) type=AlloyType.SEQINT;
else if (s==Sig.STRING) type=AlloyType.STRING;
else type = makeType(s.label, s.isOne!=null, s.isAbstract!=null, false, s.isPrivate!=null, s.isMeta!=null, s.isEnum!=null);
sig2type.put(s, type);
AlloyAtom atom = new AlloyAtom(type, (type==AlloyType.SEQINT ? Integer.MIN_VALUE : Integer.MAX_VALUE), s.label);
atom2sets.put(atom, new LinkedHashSet<AlloySet>());
sig2atom.put(s, atom);
if (s.parent!=Sig.UNIV && s.parent!=null)
ts.put(type, sigMETA(s.parent));
if (s.parent!=null)
exts.add(new AlloyTuple(atom, sig2atom.get(s.parent)));
Iterable<PrimSig> children = (s==Sig.UNIV ? toplevels : s.children());
for(PrimSig sub:children) sigMETA(sub);
return type;
}
示例5: convertValueToText
import edu.mit.csail.sdg.alloy4compiler.ast.Sig; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public String convertValueToText(Object val, boolean selected, boolean expanded, boolean leaf, int row, boolean focus) {
String c = ">";
if (onWindows) c = selected ? " style=\"color:#ffffff;\">" : " style=\"color:#000000;\">";
if (val instanceof A4Solution) return "<html> <b" + c + encode(title==null ? "" : title)+"</b></html>";
if (val instanceof Sig) {
String label = ((Sig)val).label;
if (label.startsWith("this/")) label = label.substring(5);
return "<html> <b" + c + "sig " + encode(label) + "</b></html>";
}
if (val instanceof ExprVar) return "<html> <b" + c + "set " + encode(((ExprVar)val).label) + "</b></html>";
if (val instanceof String) return "<html> <span" + c + encode((String)val) + "</span></html>";
if (val instanceof Pair) return "<html> <b" + c + "field " + encode(((ExprHasName)(((Pair<?,?>)val).b)).label) + "</b></html>";
if (val instanceof A4Tuple) {
StringBuilder sb = new StringBuilder("<html> <span" + c);
A4Tuple tp = (A4Tuple) val;
for(int i=1; i<tp.arity(); i++) {
if (i>1) sb.append(" -> ");
sb.append(encode(tp.atom(i)));
}
sb.append("</span></html>");
return sb.toString();
}
return "";
}
示例6: VizTree
import edu.mit.csail.sdg.alloy4compiler.ast.Sig; //导入依赖的package包/类
/** Constructs a tree to display the given instance. */
public VizTree(A4Solution instance, String title, int fontSize) {
super(fontSize);
this.instance = instance;
this.title = title;
this.onWindows = Util.onWindows();
ArrayList<Object> toplevel = new ArrayList<Object>();
for(Sig s: instance.getAllReachableSigs()) if (s!=Sig.UNIV && s!=Sig.SEQIDX && s!=Sig.NONE) toplevel.add(s);
for(ExprVar v: instance.getAllSkolems()) if (v.type().arity()==1 && v.label.startsWith("$")) toplevel.add(v);
Collections.sort(toplevel, new Comparator<Object>() {
public int compare(Object a, Object b) {
String t1, t2;
if (a instanceof Sig) { t1=((Sig)a).label; if (b instanceof ExprVar) return -1; else t2=((Sig)b).label; }
else { t1=((ExprVar)a).label; if (b instanceof Sig) return 1; else t2=((ExprVar)b).label; }
return Util.slashComparator.compare(t1, t2);
}
});
this.toplevel = Collections.unmodifiableList(toplevel);
do_start();
}
示例7: makeAtom
import edu.mit.csail.sdg.alloy4compiler.ast.Sig; //导入依赖的package包/类
/** Create a fresh atom for the given sig, then return the newly created atom.
* @throws ErrorAPI if attempting to add an atom to an abstract sig with children, or a builtin sig, or a subset sig.
*/
public SimAtom makeAtom(Sig sig) throws Err {
if (sig.builtin) throw new ErrorAPI("Cannot add an atom to a builtin sig.");
if (!(sig instanceof PrimSig)) throw new ErrorAPI("Cannot add an atom to a subset sig.");
PrimSig s = (PrimSig)sig;
if (s.isAbstract!=null && !s.children().isEmpty()) throw new ErrorAPI("Cannot add an atom to an abstract parent sig.");
String label = sig.label + "$";
if (label.startsWith("this/")) label=label.substring(5);
for(int i=0; ;i++) {
SimAtom atom = SimAtom.make(label + i);
if (hasAtom(atom)) continue;
SimTupleset add = SimTupleset.make(SimTuple.make(atom));
if (cacheUNIV!=null) cacheUNIV = cacheUNIV.union(add);
for(; s!=null; s=s.parent) if (!s.builtin) {
SimTupleset old = sfs.get(s);
if (old==null || old.empty()) sfs.put(s, add); else if (!add.in(old)) sfs.put(s, old.union(add)); else break;
}
return atom;
}
}
示例8: visit
import edu.mit.csail.sdg.alloy4compiler.ast.Sig; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public Object visit(ExprConstant x) throws Err {
switch(x.op) {
case NUMBER:
int n = x.num();
//[am] const
// if (n<min) throw new ErrorType(x.pos, "Current bitwidth is set to "+bitwidth+", thus this integer constant "+n+" is smaller than the minimum integer "+min);
// if (n>max) throw new ErrorType(x.pos, "Current bitwidth is set to "+bitwidth+", thus this integer constant "+n+" is bigger than the maximum integer "+max);
return n;
case FALSE: return Boolean.FALSE;
case TRUE: return Boolean.TRUE;
case MIN: return min;
case MAX: return max;
case EMPTYNESS: return SimTupleset.EMPTY;
case STRING: return SimTupleset.make(x.string);
case NEXT: return SimTupleset.makenext(min, max);
case IDEN: return cset(Sig.UNIV).iden();
}
throw new ErrorFatal(x.pos, "Unsupported operator ("+x.op+") encountered during ExprConstant.accept()");
}
示例9: visit
import edu.mit.csail.sdg.alloy4compiler.ast.Sig; //导入依赖的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);
}
示例10: getRawSIG
import edu.mit.csail.sdg.alloy4compiler.ast.Sig; //导入依赖的package包/类
/** Lookup a Sig from the current module (and it will also search this.params) */
private Sig getRawSIG (Pos pos, String name) throws Err {
List<Object> s;
Sig s2=null;
if (name.equals("sig$") || name.equals("field$")) if (world!=null) {
s2 = world.sigs.get(name);
if (s2!=null) return s2;
}
if (name.equals("univ")) return UNIV;
if (name.equals("Int")) return SIGINT;
if (name.equals("seq/Int")) return SEQIDX;
if (name.equals("String")) return STRING;
if (name.equals("none")) return NONE;
if (name.indexOf('/')<0) {
s=getRawNQS(this, 1, name);
s2=params.get(name);
} else {
if (name.startsWith("this/")) { name=name.substring(5); s2=params.get(name); }
s=getRawQS(1, name);
}
if (s2!=null && !s.contains(s2)) s.add(s2);
return (Sig) (unique(pos, name, s));
}
示例11: addModelName
import edu.mit.csail.sdg.alloy4compiler.ast.Sig; //导入依赖的package包/类
/** Add the "MODULE" declaration. */
void addModelName(Pos pos, String moduleName, List<ExprVar> list) throws Err {
if (status>0) throw new ErrorSyntax(pos,
"The \"module\" declaration must occur at the top,\n" + "and can occur at most once.");
this.moduleName = moduleName;
this.modulePos = pos;
boolean nextIsExact = false;
if (list!=null) for(ExprVar expr: list) {
if (expr==null) { nextIsExact=true; continue; }
String name = expr.label;
dup(expr.span(), name, true);
if (path.length()==0) {
Sig newSig = addSig(name, null, null, null, null, WHERE.make(expr.span()));
if (nextIsExact) exactSigs.add(newSig);
} else {
params.put(name, null);
if (nextIsExact) exactParams.add(name);
}
nextIsExact=false;
}
this.status=1; // This line must be at the end, since "addSig" will otherwise bump the status value to 3
}
示例12: rejectNameClash
import edu.mit.csail.sdg.alloy4compiler.ast.Sig; //导入依赖的package包/类
private static void rejectNameClash(final List<CompModule> modules) throws Err {
// The Alloy language forbids two overlapping sigs from having fields with the same name.
// In other words: if 2 fields have the same name, then their type's first column must not intersect.
final Map<String,List<Field>> fieldname2fields=new LinkedHashMap<String,List<Field>>();
for(CompModule m: modules) {
for(Sig sig: m.sigs.values()) {
for(Field field: sig.getFields()) {
List<Field> peers=fieldname2fields.get(field.label);
if (peers==null) { peers=new ArrayList<Field>(); fieldname2fields.put(field.label, peers); }
for(Field field2: peers)
if (field.type().firstColumnOverlaps(field2.type()))
throw new ErrorType(field.pos,
"Two overlapping signatures cannot have\n" + "two fields with the same name \""+field.label
+"\":\n\n1) one is in sig \""+field.sig+"\"\n"+field.pos
+"\n\n2) the other is in sig \""+field2.sig+"\"\n"+field2.pos);
peers.add(field);
}
}
}
}
示例13: parseField
import edu.mit.csail.sdg.alloy4compiler.ast.Sig; //导入依赖的package包/类
/** Parse field. */
private Field parseField(String id) throws IOException, Err {
final XMLNode node = nmap.get(id);
if (node==null) throw new IOException("Unknown FieldID "+id+" encountered.");
if (!node.is("field")) throw new IOException("ID "+id+" is not a field.");
String label = label(node);
Pos isPrivate = yes(node,"private") ? Pos.UNKNOWN : null;
Pos isMeta = yes(node,"meta") ? Pos.UNKNOWN : null;
Expr type = null;
for(XMLNode sub:node) if (sub.is("types")) { Expr t=parseType(sub); if (type==null) type=t; else type=type.plus(t); }
int arity;
if (type==null || (arity=type.type().arity())<2) throw new IOException("Field "+label+" is maltyped.");
String parentID = node.getAttribute("parentID");
Sig parent = id2sig.get(parentID);
if (parent==null) throw new IOException("ID "+parentID+" is not a sig.");
Field field = null;
for(Field f: parent.getFields())
if (f.label.equals(label) && f.type().arity()==arity && choices.contains(f))
{ field=f; choices.remove(f); break; }
if (field==null) field = parent.addTrickyField(Pos.UNKNOWN, isPrivate, null, null, isMeta, new String[] {label}, UNIV.join(type)) [0];
TupleSet ts = parseTuples(node, arity);
expr2ts.put(field, ts);
return field;
}
示例14: a2k
import edu.mit.csail.sdg.alloy4compiler.ast.Sig; //导入依赖的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.
}
示例15: eval
import edu.mit.csail.sdg.alloy4compiler.ast.Sig; //导入依赖的package包/类
/** If this solution is solved and satisfiable, evaluates the given expression and returns an A4TupleSet, a java Integer, or a java Boolean. */
public Object eval(Expr expr) throws Err {
try {
if (expr instanceof Sig) return eval((Sig)expr);
if (expr instanceof Field) return eval((Field)expr);
if (!solved) throw new ErrorAPI("This solution is not yet solved, so eval() is not allowed.");
if (eval==null) throw new ErrorAPI("This solution is unsatisfiable, so eval() is not allowed.");
if (expr.ambiguous && !expr.errors.isEmpty()) expr = expr.resolve(expr.type(), null);
if (!expr.errors.isEmpty()) throw expr.errors.pick();
Object result = TranslateAlloyToKodkod.alloy2kodkod(this, expr);
if (result instanceof IntExpression) return eval.evaluate((IntExpression)result) + (eval.wasOverflow() ? " (OF)" : "");
if (result instanceof Formula) return eval.evaluate((Formula)result);
if (result instanceof Expression) return new A4TupleSet(eval.evaluate((Expression)result), this);
throw new ErrorFatal("Unknown internal error encountered in the evaluator.");
} catch(CapacityExceededException ex) {
throw TranslateAlloyToKodkod.rethrow(ex);
}
}