use of edu.mit.csail.sdg.alloy4.Util.asList in project org.alloytools.alloy by AlloyTools.
the class ExprCall method getSubnodes.
/**
* {@inheritDoc}
*/
@Override
public List<? extends Browsable> getSubnodes() {
if (args.size() == 0) {
Expr b = fun.getBody();
return Util.asList(make(b.pos(), b.span(), b.getHTML(), b.getSubnodes()));
}
Pos p = pos;
if (p == Pos.UNKNOWN)
p = span();
Browsable f = make(p, p, (fun.isPred ? "<b>pred</b> " : "<b>fun</b> ") + fun.label, fun.getSubnodes());
Browsable a = make(span(), span(), "<b>" + args.size() + " argument" + (args.size() == 1 ? "</b>" : "s</b>"), args);
return Util.asList(f, a);
}
use of edu.mit.csail.sdg.alloy4.Util.asList in project org.alloytools.alloy by AlloyTools.
the class CompModule method addFunc.
/**
* Add a FUN or PRED declaration.
*/
void addFunc(Pos p, Pos isPrivate, String n, Expr f, List<Decl> decls, Expr t, Expr v) throws Err {
if (decls == null)
decls = new ArrayList<Decl>();
else
decls = new ArrayList<Decl>(decls);
if (f != null)
decls.add(0, new Decl(null, null, null, Util.asList(ExprVar.make(f.span(), "this")), f));
for (Decl d : decls) {
if (d.isPrivate != null) {
ExprHasName name = d.names.get(0);
throw new ErrorSyntax(d.isPrivate.merge(name.pos), "Function parameter \"" + name.label + "\" is always private already.");
}
if (d.disjoint2 != null) {
ExprHasName name = d.names.get(d.names.size() - 1);
throw new ErrorSyntax(d.disjoint2.merge(name.pos), "Function parameter \"" + name.label + "\" cannot be bound to a 'disjoint' expression.");
}
}
status = 3;
dup(p, n, false);
ExprHasName dup = Decl.findDuplicateName(decls);
if (dup != null)
throw new ErrorSyntax(dup.span(), "The parameter name \"" + dup.label + "\" cannot appear more than once.");
Func ans = new Func(p, isPrivate, n, decls, t, v);
ArrayList<Func> list = funcs.get(n);
if (list == null) {
list = new ArrayList<Func>();
funcs.put(n, list);
}
list.add(ans);
}
use of edu.mit.csail.sdg.alloy4.Util.asList in project org.alloytools.alloy by AlloyTools.
the class CompModule method populate.
/**
* Resolve the name based on the current context and this module.
*/
private Expr populate(TempList<Expr> ch, TempList<String> re, Decl rootfield, Sig rootsig, boolean rootfunparam, Func rootfunbody, Pos pos, String fullname, Expr THIS) {
// Return object can be Func(with > 0 arguments) or Expr
final String name = (fullname.charAt(0) == '@') ? fullname.substring(1) : fullname;
boolean fun = (rootsig != null && (rootfield == null || rootfield.expr.mult() == ExprUnary.Op.EXACTLYOF)) || (rootsig == null && !rootfunparam);
if (name.equals("univ"))
return ExprUnary.Op.NOOP.make(pos, UNIV);
if (name.equals("Int"))
return ExprUnary.Op.NOOP.make(pos, SIGINT);
if (name.equals("seq/Int"))
return ExprUnary.Op.NOOP.make(pos, SEQIDX);
if (name.equals("String"))
return ExprUnary.Op.NOOP.make(pos, STRING);
if (name.equals("none"))
return ExprUnary.Op.NOOP.make(pos, NONE);
if (name.equals("iden"))
return ExprConstant.Op.IDEN.make(pos, 0);
if (name.equals("sig$") || name.equals("field$"))
if (world != null) {
Sig s = world.sigs.get(name);
if (s != null)
return ExprUnary.Op.NOOP.make(pos, s);
}
final List<Object> ans = name.indexOf('/') >= 0 ? getRawQS(fun ? 5 : 1, name) : getRawNQS(this, fun ? 5 : 1, name);
final Sig param = params.get(name);
if (param != null && !ans.contains(param))
ans.add(param);
for (Object x : ans) {
if (x instanceof Sig) {
Sig y = (Sig) x;
ch.add(ExprUnary.Op.NOOP.make(pos, y, null, 0));
re.add("sig " + y.label);
} else if (x instanceof Func) {
Func f = (Func) x;
int fn = f.count();
int penalty = 0;
if (resolution == 1 && fn > 0 && rootsig != null && THIS != null && THIS.type().hasArity(1) && f.get(0).type().intersects(THIS.type())) {
// If we're inside a sig, and there is a unary variable
// bound to "this",
// we should consider it as a possible FIRST ARGUMENT of a
// fun/pred call
ConstList<Expr> t = Util.asList(THIS);
// penalty
ch.add(fn == 1 ? ExprCall.make(pos, null, f, t, 1 + penalty) : ExprBadCall.make(pos, null, f, t, 1 + penalty));
// of
// 1
re.add((f.isPred ? "pred this." : "fun this.") + f.label);
}
if (resolution == 1) {
ch.add(fn == 0 ? ExprCall.make(pos, null, f, null, penalty) : ExprBadCall.make(pos, null, f, null, penalty));
re.add((f.isPred ? "pred " : "fun ") + f.label);
}
if (resolution == 2 && f != rootfunbody && THIS != null && fullname.charAt(0) != '@' && fn > 0 && f.get(0).type().intersects(THIS.type())) {
// If there is some value bound to "this", we should
// consider it as a possible FIRST ARGUMENT of a fun/pred
// call
ConstList<Expr> t = Util.asList(THIS);
ch.add(fn == 1 ? ExprCall.make(pos, null, f, t, 0) : ExprBadCall.make(pos, null, f, t, 0));
re.add((f.isPred ? "pred this." : "fun this.") + f.label);
}
if (resolution != 1) {
ch.add(fn == 0 ? ExprCall.make(pos, null, f, null, 0) : ExprBadCall.make(pos, null, f, null, 0));
re.add((f.isPred ? "pred " : "fun ") + f.label);
}
}
}
// All else: we can call, and can refer to anything visible.
for (CompModule m : getAllNameableModules()) for (Sig s : m.sigs.values()) if (m == this || s.isPrivate == null)
for (Field f : s.getFields()) if (f.isMeta == null && (m == this || f.isPrivate == null) && f.label.equals(name))
if (resolution == 1) {
Expr x = null;
if (rootsig == null) {
x = ExprUnary.Op.NOOP.make(pos, f, null, 0);
} else if (rootsig.isSameOrDescendentOf(f.sig)) {
x = ExprUnary.Op.NOOP.make(pos, f, null, 0);
if (fullname.charAt(0) != '@')
x = THIS.join(x);
} else if (rootfield == null || rootfield.expr.mult() == ExprUnary.Op.EXACTLYOF) {
x = ExprUnary.Op.NOOP.make(pos, f, null, 1);
}
// penalty of 1
if (x != null) {
ch.add(x);
re.add("field " + f.sig.label + " <: " + f.label);
}
} else if (rootfield == null || rootsig.isSameOrDescendentOf(f.sig)) {
Expr x0 = ExprUnary.Op.NOOP.make(pos, f, null, 0);
if (resolution == 2 && THIS != null && fullname.charAt(0) != '@' && f.type().firstColumnOverlaps(THIS.type())) {
ch.add(THIS.join(x0));
re.add("field " + f.sig.label + " <: this." + f.label);
if (rootsig != null)
continue;
}
ch.add(x0);
re.add("field " + f.sig.label + " <: " + f.label);
}
if (metaSig() != null && (rootsig == null || rootfield == null)) {
SafeList<PrimSig> children = null;
try {
children = metaSig().children();
} catch (Err err) {
return null;
}
// exception NOT possible
for (PrimSig s : children) for (Field f : s.getFields()) if (f.label.equals(name)) {
Expr x = ExprUnary.Op.NOOP.make(pos, f, null, 0);
ch.add(x);
re.add("field " + f.sig.label + " <: " + f.label);
}
}
if (metaField() != null && (rootsig == null || rootfield == null)) {
SafeList<PrimSig> children = null;
try {
children = metaField().children();
} catch (Err err) {
return null;
}
// exception NOT possible
for (PrimSig s : children) for (Field f : s.getFields()) if (f.label.equals(name)) {
Expr x = ExprUnary.Op.NOOP.make(pos, f, null, 0);
ch.add(x);
re.add("field " + f.sig.label + " <: " + f.label);
}
}
return null;
}
use of edu.mit.csail.sdg.alloy4.Util.asList in project org.alloytools.alloy by AlloyTools.
the class VizCustomizationPanel method createGeneralWidget.
// =============================================================================================================//
/**
* Generates the "general graph settings" widgets, and add them to "parent".
*/
private void createGeneralWidget(JPanel parent) {
final List<Integer> fontSizes = Util.asList(9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 32, 36, 40, 44, 48, 54, 60, 66, 72);
JLabel nLabel = OurUtil.label("Node Color Palette:");
JLabel eLabel = OurUtil.label("Edge Color Palette:");
JLabel aLabel = OurUtil.label("Use original atom names:");
JLabel pLabel = OurUtil.label("Hide private sigs/relations:");
JLabel mLabel = OurUtil.label("Hide meta sigs/relations:");
JLabel fLabel = OurUtil.label("Font Size:");
JComboBox fontSize = new OurCombobox(false, fontSizes.toArray(), 60, 32, vizState.getFontSize()) {
private static final long serialVersionUID = 0;
@Override
public void do_changed(Object value) {
if (fontSizes.contains(value))
vizState.setFontSize((Integer) value);
}
};
JComboBox nodepal = new OurCombobox(false, DotPalette.values(), 100, 32, vizState.getNodePalette()) {
private static final long serialVersionUID = 0;
@Override
public String do_getText(Object value) {
return ((DotPalette) value).getDisplayedText();
}
@Override
public void do_changed(Object value) {
vizState.setNodePalette((DotPalette) value);
}
};
JComboBox edgepal = new OurCombobox(false, DotPalette.values(), 100, 32, vizState.getEdgePalette()) {
private static final long serialVersionUID = 0;
@Override
public String do_getText(Object value) {
return ((DotPalette) value).getDisplayedText();
}
@Override
public void do_changed(Object value) {
vizState.setEdgePalette((DotPalette) value);
}
};
JPanel name = new OurCheckbox("", "Whether the visualizer should use the original atom names as-is.", vizState.useOriginalName() ? OurCheckbox.ON : OurCheckbox.OFF) {
private static final long serialVersionUID = 0;
@Override
public Icon do_action() {
boolean x = vizState.useOriginalName();
vizState.useOriginalName(!x);
return (!x ? ON : OFF);
}
};
JPanel priv = new OurCheckbox("", "Whether the visualizer should hide private sigs, sets, and relations by default.", vizState.hidePrivate() ? OurCheckbox.ON : OurCheckbox.OFF) {
private static final long serialVersionUID = 0;
@Override
public Icon do_action() {
boolean x = vizState.hidePrivate();
vizState.hidePrivate(!x);
remakeAll();
return (!x ? ON : OFF);
}
};
JPanel meta = new OurCheckbox("", "Whether the visualizer should hide meta sigs, sets, and relations by default.", vizState.hideMeta() ? OurCheckbox.ON : OurCheckbox.OFF) {
private static final long serialVersionUID = 0;
@Override
public Icon do_action() {
boolean x = vizState.hideMeta();
vizState.hideMeta(!x);
remakeAll();
return (!x ? ON : OFF);
}
};
parent.add(makelabel(" General Graph Settings:"));
parent.add(OurUtil.makeH(wcolor, new Dimension(6, 6)));
parent.add(OurUtil.makeH(wcolor, 25, nLabel, 5, nodepal, 8, aLabel, 5, name, 2, null));
parent.add(OurUtil.makeH(wcolor, 25, eLabel, 5, edgepal, 8, fLabel, 5, fontSize, 2, null));
parent.add(OurUtil.makeH(wcolor, 25, pLabel, 5, priv, 2, null));
parent.add(OurUtil.makeH(wcolor, 25, mLabel, 5, meta, 2, null));
}
Aggregations