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);
ch.add(fn==1 ? ExprCall.make(pos, null, f, t, 1+penalty) : ExprBadCall.make(pos, null, f, t, 1+penalty)); // 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);
}
}
}
// Within a field decl
// (1) Can refer to any visible sig/param (but you cannot call any function or predicates)
// (2) Can refer to field in this sig (defined earlier than you), and fields in any visible ancestor sig
// Within an appended facts
// (1) Can refer to any visible sig/param/func/predicate
// (2) Can refer to any visible field
// Within a function paramDecl/returnDecl
// (1) Cannot call
// (2) But can refer to anything else visible.
// 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);