use of com.gzoumix.semisolver.constraint.Constraint in project abstools by abstools.
the class ContractInference method typeInference.
public ResultInferenceStmt typeInference(Block b) {
_log.logDebug("Contract Inference for the Block");
_log.beginIndent();
_env.newScope();
// accumulate contracts and constraint.Constraints
// in the resulting output
ResultInferenceStmt resStmt = null;
Constraint c = _df.newConstraint();
Contract contract = _df.newContractEmpty();
List<TypingEnvironment> envs = new LinkedList<>();
envs.add(_env);
for (Stmt s : b.getStmts()) {
List<TypingEnvironment> cumul = new LinkedList<>();
Contract current = null;
for (TypingEnvironment tmpEnv : envs) {
_env = tmpEnv;
resStmt = typeInference(s);
c.add(resStmt.getConstraint());
cumul.addAll(resStmt.getEnvironment());
current = (current == null) ? resStmt.getContract() : _df.newContractUnion(b, current, resStmt.getContract());
}
envs = cumul;
contract.add(current);
}
_log.endIndent();
_log.logDebug("Block Sub-Expression Finished");
for (TypingEnvironment env : envs) {
env.popScope();
}
return new ResultInferenceStmt(contract, c, envs);
}
use of com.gzoumix.semisolver.constraint.Constraint in project abstools by abstools.
the class ContractInference method typeInference.
public ResultInferenceStmt typeInference(IfStmt ifstmt) {
_log.logDebug("Contract inference of a Conditional Statement");
_log.beginIndent();
TypingEnvironment tmp = _env.copy();
ResultInferenceStmt resThen = typeInference(ifstmt.getThen());
List<TypingEnvironment> resultEnvs = new LinkedList<>();
resultEnvs.addAll(resThen.getEnvironment());
Contract contract;
Constraint c = resThen.getConstraint();
if (ifstmt.hasElse()) {
this._env = tmp;
ResultInferenceStmt resElse = typeInference(ifstmt.getElse());
c.add(resElse.getConstraint());
resultEnvs.addAll(resElse.getEnvironment());
contract = _df.newContractUnion(ifstmt, resThen.getContract(), resElse.getContract());
} else {
resultEnvs.add(tmp);
contract = _df.newContractUnion(ifstmt, resThen.getContract(), _df.newContractEmpty());
}
_log.endIndent();
_log.logDebug("IfStmt Sub-Statments Finished");
return new ResultInferenceStmt(contract, c, resultEnvs);
}
use of com.gzoumix.semisolver.constraint.Constraint in project abstools by abstools.
the class ContractInference method typeInference.
// /////////////////////////////////////////////////////////////////////////////
// 2.2. Declarations
public ResultInferenceStmt typeInference(VarDecl vd) {
_log.logDebug("Contract Inference for the VarDecl \"" + vd.getName() + "\"");
_log.beginIndent();
Contract contract;
Constraint c;
ITypingEnvironmentVariableType X;
if (vd.hasInitExp()) {
Exp exp = vd.getInitExp();
if (exp instanceof PureExp) {
ResultInferencePureExp resInitExp = typeInferenceAsPure((PureExp) exp);
contract = _df.newContractEmpty();
c = _df.newConstraint();
X = resInitExp.getVariableType();
} else {
ResultInferenceEffExp resInitExp = typeInference((EffExp) exp);
contract = resInitExp.getContract();
c = resInitExp.getConstraint();
X = resInitExp.getRecord();
}
} else {
contract = _df.newContractEmpty();
c = _df.newConstraint();
X = _df.newRecordVariable();
}
_env.putVariable(vd.getName(), X);
return new ResultInferenceStmt(contract, c, _env);
}
use of com.gzoumix.semisolver.constraint.Constraint in project abstools by abstools.
the class ContractInference method typeInference.
public ResultInferenceStmt typeInference(ReturnStmt res) {
_log.logDebug("Contract Inference for the ReturnStmt");
_log.beginIndent();
ResultInferenceEffExp resRetExp = typeInference(res.getRetExp());
_log.endIndent();
_log.logDebug("ReturnStmt Sub-Expression Finished");
Contract contract = resRetExp.getContract();
Constraint c = resRetExp.getConstraint();
c.addEquation(new ASTNodeInformation(res), _env.getVariableRecord(_destinyName), _env.getRecord(resRetExp.getRecord()));
return new ResultInferenceStmt(contract, c, resRetExp.getEnvironment());
}
use of com.gzoumix.semisolver.constraint.Constraint in project abstools by abstools.
the class ContractInference method typeInference.
public ResultInferenceEffExp typeInference(GetExp exp) {
_log.logDebug("Contract Inference for a GetExp");
_log.beginIndent();
// 1. first is calculate the inference of the expression 'e' of 'e.get'
ResultInferencePureExp resPureExp = typeInferenceAsPure(exp.getPureExp());
_log.endIndent();
_log.logDebug("GetExp Sub-Expression Finished");
Contract contract;
Constraint c = _df.newConstraint();
// 2. record for the result
GroupName aprime = _df.newGroupName();
IRecord X = _df.newRecordVariable();
// 3. check if future is tick
ITypingEnvironmentVariableType variableType = resPureExp.getVariableType();
if (variableType instanceof TypingEnvironmentVariableTypeFuture) {
ITypingEnvironmentFutureType fType = _env.getFuture((TypingEnvironmentVariableTypeFuture) variableType);
if (fType instanceof TypingEnvironmentFutureTypeUntick) {
_env.putFuture((TypingEnvironmentVariableTypeFuture) variableType, new TypingEnvironmentFutureTypeTick(fType.getRecord()));
contract = _df.newContract(_df.newContractElementParallel(_df.newContractInvkG(exp, ((TypingEnvironmentFutureTypeUntick) fType).getContract(), new ContractElementGet(exp, _a, aprime)), _env.unsync(exp)));
} else {
contract = _df.newContractEmpty();
}
try {
c.addEquation(new ASTNodeInformation(exp), _df.newRecordFuture(aprime, X), fType.getRecord());
} catch (Exception e) {
e.getMessage();
}
} else {
contract = _df.newContractEmpty();
}
return new ResultInferenceEffExp(X, contract, c, _env);
}
Aggregations