本文整理汇总了Java中edu.mit.csail.sdg.alloy4.A4Reporter.typecheck方法的典型用法代码示例。如果您正苦于以下问题:Java A4Reporter.typecheck方法的具体用法?Java A4Reporter.typecheck怎么用?Java A4Reporter.typecheck使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.mit.csail.sdg.alloy4.A4Reporter
的用法示例。
在下文中一共展示了A4Reporter.typecheck方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveAssertions
import edu.mit.csail.sdg.alloy4.A4Reporter; //导入方法依赖的package包/类
/**
* Each assertion name now points to a typechecked Expr rather than an
* untypechecked Exp.
*/
private JoinableList<Err> resolveAssertions(A4Reporter rep, JoinableList<Err> errors, List<ErrorWarning> warns)
throws Err {
Context cx = new Context(this, warns);
for (Map.Entry<String,Expr> e : asserts.entrySet()) {
Expr expr = e.getValue();
expr = cx.check(expr).resolve_as_formula(warns);
if (expr.errors.isEmpty()) {
e.setValue(expr);
rep.typecheck("Assertion " + e.getKey() + ": " + expr.type() + "\n");
} else
errors = errors.make(expr.errors);
}
return errors;
}
示例2: resolveFacts
import edu.mit.csail.sdg.alloy4.A4Reporter; //导入方法依赖的package包/类
/**
* Each fact name now points to a typechecked Expr rather than an
* untypechecked Exp; we'll also add the sig appended facts.
*/
private JoinableList<Err> resolveFacts(CompModule res, A4Reporter rep, JoinableList<Err> errors,
List<ErrorWarning> warns) throws Err {
Context cx = new Context(this, warns);
for (int i = 0; i < facts.size(); i++) {
String name = facts.get(i).a;
Expr expr = facts.get(i).b;
Expr checked = cx.check(expr);
expr = checked.resolve_as_formula(warns);
if (expr.errors.isEmpty()) {
facts.set(i, new Pair<String,Expr>(name, expr));
rep.typecheck("Fact " + name + ": " + expr.type() + "\n");
} else
errors = errors.make(expr.errors);
}
for (Sig s : sigs.values()) {
Expr f = res.old2appendedfacts.get(res.new2old.get(s));
if (f == null)
continue;
if (f instanceof ExprConstant && ((ExprConstant) f).op == ExprConstant.Op.TRUE)
continue;
Expr formula;
cx.rootsig = s;
if (s.isOne == null) {
cx.put("this", s.decl.get());
formula = cx.check(f).resolve_as_formula(warns);
} else {
cx.put("this", s);
formula = cx.check(f).resolve_as_formula(warns);
}
cx.remove("this");
if (formula.errors.size() > 0)
errors = errors.make(formula.errors);
else {
s.addFact(formula);
rep.typecheck("Fact " + s + "$fact: " + formula.type() + "\n");
}
}
return errors;
}
示例3: resolveFuncBody
import edu.mit.csail.sdg.alloy4.A4Reporter; //导入方法依赖的package包/类
/** Each Func's body will now be typechecked Expr object. */
private JoinableList<Err> resolveFuncBody(A4Reporter rep, JoinableList<Err> errors, List<ErrorWarning> warns) throws Err {
for(ArrayList<Func> entry: funcs.values()) for(Func ff: entry) {
Context cx = new Context(this, warns);
cx.rootfunbody = ff;
for(Decl d: ff.decls) for(ExprHasName n: d.names) cx.put(n.label, n);
Expr newBody = cx.check(ff.getBody());
if (ff.isPred)
newBody = newBody.resolve_as_formula(warns);
else
newBody = newBody.resolve_as_set(warns);
errors = errors.make(newBody.errors);
if (!newBody.errors.isEmpty()) continue;
try { ff.setBody(newBody); } catch(Err er) {errors = errors.make(er); continue;}
if (warns!=null && ff.returnDecl.type().hasTuple() && newBody.type().hasTuple() && !newBody.type().intersects(ff.returnDecl.type()))
warns.add(new ErrorWarning(newBody.span(),
"Function return value is disjoint from its return type.\n"
+"Function body has type "+newBody.type() + "\n" + "but the return type is "+ff.returnDecl.type()));
//else if (warns!=null && Version.experimental && !newBody.type.isSubtypeOf(ff.returnDecl.type))
// warns.add(new ErrorWarning(newBody.span(),
// "Function may return a tuple not in its declared return type.\n"
// +"The Alloy Analyzer's analysis may be unsound\n"
// +"if it returns a tuple outside its declared return type.\n"
// +"Function body has type "+newBody.type+"\nbut the return type is "+ff.returnDecl.type));
rep.typecheck(ff.toString()+", BODY:"+newBody.type()+"\n");
}
return errors;
}
示例4: resolveAssertions
import edu.mit.csail.sdg.alloy4.A4Reporter; //导入方法依赖的package包/类
/** Each assertion name now points to a typechecked Expr rather than an untypechecked Exp. */
private JoinableList<Err> resolveAssertions(A4Reporter rep, JoinableList<Err> errors, List<ErrorWarning> warns) throws Err {
Context cx = new Context(this, warns);
for(Map.Entry<String,Expr> e: asserts.entrySet()) {
Expr expr = e.getValue();
expr = cx.check(expr).resolve_as_formula(warns);
if (expr.errors.isEmpty()) {
e.setValue(expr);
rep.typecheck("Assertion " + e.getKey() + ": " + expr.type()+"\n");
} else errors = errors.make(expr.errors);
}
return errors;
}
示例5: resolveFacts
import edu.mit.csail.sdg.alloy4.A4Reporter; //导入方法依赖的package包/类
/** Each fact name now points to a typechecked Expr rather than an untypechecked Exp; we'll also add the sig appended facts. */
private JoinableList<Err> resolveFacts(CompModule res, A4Reporter rep, JoinableList<Err> errors, List<ErrorWarning> warns) throws Err {
Context cx = new Context(this, warns);
for(int i=0; i<facts.size(); i++) {
String name = facts.get(i).a;
Expr expr = facts.get(i).b;
expr = cx.check(expr).resolve_as_formula(warns);
if (expr.errors.isEmpty()) {
facts.set(i, new Pair<String,Expr>(name, expr));
rep.typecheck("Fact " + name + ": " + expr.type()+"\n");
} else errors = errors.make(expr.errors);
}
for(Sig s: sigs.values()) {
Expr f = res.old2appendedfacts.get(res.new2old.get(s));
if (f == null) continue;
if (f instanceof ExprConstant && ((ExprConstant)f).op==ExprConstant.Op.TRUE) continue;
Expr formula;
cx.rootsig = s;
if (s.isOne==null) {
cx.put("this", s.decl.get());
formula = cx.check(f).resolve_as_formula(warns);
} else {
cx.put("this", s);
formula = cx.check(f).resolve_as_formula(warns);
}
cx.remove("this");
if (formula.errors.size()>0) errors = errors.make(formula.errors); else { s.addFact(formula); rep.typecheck("Fact "+s+"$fact: " + formula.type()+"\n"); }
}
return errors;
}
示例6: resolveFieldDecl
import edu.mit.csail.sdg.alloy4.A4Reporter; //导入方法依赖的package包/类
private static void resolveFieldDecl(CompModule res, final A4Reporter rep, final Sig s, final List<ErrorWarning> warns, boolean defined) throws Err {
// When typechecking each field:
// * it is allowed to refer to earlier fields in the same SIG or in any visible ancestor sig
// * it is allowed to refer to visible sigs
// * it is NOT allowed to refer to any predicate or function
// For example, if A.als opens B.als, and B/SIGX extends A/SIGY,
// then B/SIGX's fields cannot refer to A/SIGY, nor any fields in A/SIGY)
final List<Decl> oldDecls = res.old2fields.get(res.new2old.get(s));
if (oldDecls==null) return;
final CompModule m = res.sig2module.get(s);
final Context cx = new Context(m, warns);
final ExprHasName dup = Decl.findDuplicateName(oldDecls);
if (dup!=null) throw new ErrorSyntax(dup.span(), "sig \""+s+"\" cannot have 2 fields named \""+dup.label+"\"");
for(final Decl d: oldDecls) {
if (d.expr.mult()!=ExprUnary.Op.EXACTLYOF) {if (defined) continue;} else {if (!defined) continue;}
// The name "this" does matter, since the parser and the typechecker both refer to it as "this"
cx.rootfield = d;
cx.rootsig = s;
cx.put("this", s.decl.get());
Expr bound = cx.check(d.expr).resolve_as_set(warns);
cx.remove("this");
String[] names = new String[d.names.size()]; for(int i=0; i<names.length; i++) names[i] = d.names.get(i).label;
Field[] fields = s.addTrickyField(d.span(), d.isPrivate, d.disjoint, d.disjoint2, null, names, bound);
for(Field f: fields) {
rep.typecheck("Sig "+s+", Field "+f.label+": "+f.type()+"\n");
}
}
}
示例7: resolveFuncDecls
import edu.mit.csail.sdg.alloy4.A4Reporter; //导入方法依赖的package包/类
/** Each FunAST will now point to a bodyless Func object. */
private JoinableList<Err> resolveFuncDecls(A4Reporter rep, JoinableList<Err> errors, List<ErrorWarning> warns)
throws Err {
for (ArrayList<Func> list : funcs.values()) {
for (int listi = 0; listi < list.size(); listi++) {
Func f = list.get(listi);
String fullname = (path.length() == 0 ? "this/" : (path + "/")) + f.label;
// Each PARAMETER can refer to earlier parameter in the same
// function, and any SIG or FIELD visible from here.
// Each RETURNTYPE can refer to the parameters of the same
// function, and any SIG or FIELD visible from here.
Context cx = new Context(this, warns);
cx.rootfunparam = true;
TempList<Decl> tmpdecls = new TempList<Decl>();
boolean err = false;
for (Decl d : f.decls) {
TempList<ExprVar> tmpvars = new TempList<ExprVar>();
Expr val = cx.check(d.expr).resolve_as_set(warns);
if (!val.errors.isEmpty()) {
err = true;
errors = errors.make(val.errors);
}
for (ExprHasName n : d.names) {
ExprVar v = ExprVar.make(n.span(), n.label, val.type());
cx.put(n.label, v);
tmpvars.add(v);
rep.typecheck((f.isPred ? "pred " : "fun ") + fullname + ", Param " + n.label + ": " + v.type()
+ "\n");
}
tmpdecls.add(new Decl(d.isPrivate, d.disjoint, d.disjoint2, tmpvars.makeConst(), val));
}
Expr ret = null;
if (!f.isPred) {
ret = cx.check(f.returnDecl).resolve_as_set(warns);
if (!ret.errors.isEmpty()) {
err = true;
errors = errors.make(ret.errors);
}
}
if (err)
continue;
try {
f = new Func(f.pos, f.isPrivate, fullname, tmpdecls.makeConst(), ret, f.getBody());
list.set(listi, f);
rep.typecheck("" + f + ", RETURN: " + f.returnDecl.type() + "\n");
} catch (Err ex) {
errors = errors.make(ex);
}
}
}
return errors;
}
示例8: resolveFuncBody
import edu.mit.csail.sdg.alloy4.A4Reporter; //导入方法依赖的package包/类
/** Each Func's body will now be typechecked Expr object. */
private JoinableList<Err> resolveFuncBody(A4Reporter rep, JoinableList<Err> errors, List<ErrorWarning> warns)
throws Err {
for (ArrayList<Func> entry : funcs.values())
for (Func ff : entry) {
Context cx = new Context(this, warns);
cx.rootfunbody = ff;
for (Decl d : ff.decls)
for (ExprHasName n : d.names)
cx.put(n.label, n);
Expr newBody = cx.check(ff.getBody());
if (ff.isPred)
newBody = newBody.resolve_as_formula(warns);
else
newBody = newBody.resolve_as_set(warns);
errors = errors.make(newBody.errors);
if (!newBody.errors.isEmpty())
continue;
try {
ff.setBody(newBody);
} catch (Err er) {
errors = errors.make(er);
continue;
}
if (warns != null && ff.returnDecl.type().hasTuple() && newBody.type().hasTuple()
&& !newBody.type().intersects(ff.returnDecl.type()))
warns.add(new ErrorWarning(newBody.span(),
"Function return value is disjoint from its return type.\n" + "Function body has type "
+ newBody.type() + "\n" + "but the return type is " + ff.returnDecl.type()));
// else if (warns!=null && Version.experimental &&
// !newBody.type.isSubtypeOf(ff.returnDecl.type))
// warns.add(new ErrorWarning(newBody.span(),
// "Function may return a tuple not in its declared return
// type.\n"
// +"The Alloy Analyzer's analysis may be unsound\n"
// +"if it returns a tuple outside its declared return type.\n"
// +"Function body has type "+newBody.type+"\nbut the return
// type is "+ff.returnDecl.type));
rep.typecheck(ff.toString() + ", BODY:" + newBody.type() + "\n");
}
return errors;
}
示例9: resolveFieldDecl
import edu.mit.csail.sdg.alloy4.A4Reporter; //导入方法依赖的package包/类
private static void resolveFieldDecl(CompModule res, final A4Reporter rep, final Sig s,
final List<ErrorWarning> warns, boolean defined) throws Err {
// When typechecking each field:
// * it is allowed to refer to earlier fields in the same SIG or in any
// visible ancestor sig
// * it is allowed to refer to visible sigs
// * it is NOT allowed to refer to any predicate or function
// For example, if A.als opens B.als, and B/SIGX extends A/SIGY,
// then B/SIGX's fields cannot refer to A/SIGY, nor any fields in
// A/SIGY)
final List<Decl> oldDecls = res.old2fields.get(res.new2old.get(s));
if (oldDecls == null)
return;
final CompModule m = res.sig2module.get(s);
final Context cx = new Context(m, warns);
final ExprHasName dup = Decl.findDuplicateName(oldDecls);
if (dup != null)
throw new ErrorSyntax(dup.span(), "sig \"" + s + "\" cannot have 2 fields named \"" + dup.label + "\"");
for (final Decl d : oldDecls) {
if (d.expr.mult() != ExprUnary.Op.EXACTLYOF) {
if (defined)
continue;
} else {
if (!defined)
continue;
}
// The name "this" does matter, since the parser and the typechecker
// both refer to it as "this"
cx.rootfield = d;
cx.rootsig = s;
cx.put("this", s.decl.get());
Expr bound = cx.check(d.expr).resolve_as_set(warns);
cx.remove("this");
String[] names = new String[d.names.size()];
for (int i = 0; i < names.length; i++)
names[i] = d.names.get(i).label;
Field[] fields = s.addTrickyField(d.span(), d.isPrivate, d.disjoint, d.disjoint2, null, names, bound);
for (Field f : fields) {
rep.typecheck("Sig " + s + ", Field " + f.label + ": " + f.type() + "\n");
}
}
}