use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class L42 method runSlow.
public static ErrorMessage.FinalResult runSlow(String fileName, String code) {
try {
L42.setExecutionStage(ExecutionStage.Parsing);
Expression code1 = Parser.parse(fileName, code);
assert code1 instanceof Expression.ClassB || code1 instanceof Expression.ClassReuse;
L42.setExecutionStage(ExecutionStage.CheckingWellFormedness);
auxiliaryGrammar.WellFormedness.checkAll(code1);
L42.setExecutionStage(ExecutionStage.Desugaring);
Expression code2 = Desugar.of(code1);
assert auxiliaryGrammar.WellFormedness.checkAll(code2);
ExpCore.ClassB code3 = (ExpCore.ClassB) code2.accept(new InjectionOnCore());
assert coreVisitors.CheckNoVarDeclaredTwice.of(code3);
// L42.usedNames.addAll(CollectDeclaredVarsAndCheckNoDeclaredTwice.of(code2));
//L42.usedNames.addAll(CollectDeclaredClassNamesAndMethodNames.of(code2));
L42.setExecutionStage(ExecutionStage.MetaExecution);
//ClassB result= (ClassB)Executor.stepStar(exe,code3);
//Refresh of position identities, it is used to generate correct Java code.
code3 = (ClassB) code3.accept(new CloneVisitor() {
@Override
public ExpCore visit(ClassB cb) {
Position p = cb.getP();
cb = cb.withP(new Position(p.getFile(), p.getLine1(), p.getPos1(), p.getLine2(), p.getPos2(), p.get_next()));
return super.visit(cb);
}
});
//ClassB result= Configuration.reduction.of(code3);
ClassB result = ProgramReduction.allSteps(code3);
//System.out.println("--------------------------");
return checkFinalError(result);
} finally {
L42.setExecutionStage(ExecutionStage.None);
}
}
use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class TsLibrary method memberMethod.
default default TOutM memberMethod(TIn in, List<Type> supertypes, MethodWithType mwt) {
//(member method)
//Phase| p| Ps |-M ~> M'
// where
// M =refine? mdf method T m(T1 x1 .. Tn xn)exceptions Ps0 e?
// M'=refine? mdf method T m(T1 x1 .. Tn xn)exceptions Ps0 e?'
// G=this:mdf This0,x1:T1,..,xn:Tn
// if e?=e then
// Typed| p| G |- e ~> e?':_ <=fwd% T | empty;Ps1
// forall P1 in Ps1 exists P0 in Ps0 such that p|-P1<=P0
//else
// e?=e?'
MethodWithType mwt1;
if (!mwt.get_inner().isPresent()) {
mwt1 = mwt;
} else {
TIn newIn = in.freshGFromMt(mwt);
TOut out = type(newIn);
if (!out.isOk()) {
return out.toError();
}
for (Path P1 : out.toOk().exceptions) {
//exists P0 in Ps0 such that p|-P1<=P0
boolean ok = mwt.getMt().getExceptions().stream().anyMatch(P0 -> null == TypeSystem.subtype(newIn.p, P1, P0.getPath()));
if (!ok) {
return new TErr(newIn, "", P1.toImmNT(), ErrorKind.MethodLeaksExceptions);
}
}
if (!out.toOk().returns.isEmpty()) {
return new TErr(newIn, "", out.toOk().returns.get(0), ErrorKind.MethodLeaksReturns);
}
mwt1 = mwt.with_inner(Optional.of(out.toOk().annotated));
}
if (mwt.getMt().isRefine()) {
// /or method declares an exception (P) which is not a subtype of ancestor exceptions
for (Type t : supertypes) {
Path P = t.getPath();
ClassB cbP = in.p.extractClassB(P);
MethodWithType mwtP = (MethodWithType) cbP._getMember(mwt.getMs());
if (mwtP == null) {
continue;
}
MethodType M0 = From.from(mwtP.getMt(), P);
ErrorKind kind = TypeSystem.subtype(in.p, mwt.getMt().getReturnType(), M0.getReturnType());
if (kind != null) {
return new TErr(in, "", P.toImmNT(), ErrorKind.InvalidImplements);
}
{
int i = -1;
for (Type Ti : mwt.getMt().getTs()) {
i += 1;
Type T1i = M0.getTs().get(i);
if (!in.p.equiv(Ti, T1i)) {
return new TErr(in, "", P.toImmNT(), ErrorKind.InvalidImplements);
}
}
}
for (Type Pi : mwt.getMt().getExceptions()) {
//exists Pj in Ps' such that p |- Pi<=Pj
boolean ok = M0.getExceptions().stream().anyMatch(Pj -> null == TypeSystem.subtype(in.p, Pi.getPath(), Pj.getPath()));
if (!ok) {
return new TErr(in, "", P.toImmNT(), ErrorKind.InvalidImplements);
}
}
}
}
return new TOkM(mwt1);
}
use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class TsLibrary method coherent.
static boolean coherent(Program p, boolean force) {
ClassB top = p.top();
if (top.isInterface()) {
return true;
}
List<MethodWithType> stateC = top.mwts().stream().map(m -> (MethodWithType) m).filter(m -> !m.get_inner().isPresent()).sorted((m1, m2) -> m1.getMt().getMdf() == Mdf.Class ? -1 : 1).collect(Collectors.toList());
if (stateC.isEmpty()) {
return true;
}
MethodWithType ck = stateC.get(0);
if (!coherentK(p, ck)) {
if (force) {
throw new ErrorMessage.NotOkToStar(top, ck, "invalid candidate factory", ck.getP());
}
return false;
}
for (MethodWithType mwt : stateC.subList(1, stateC.size())) {
if (!coherentF(p, ck, mwt)) {
if (force) {
throw new ErrorMessage.NotOkToStar(top, ck, "abstract method\n" + sugarVisitors.ToFormattedText.of(mwt) + "\ndo not fit candidate factory", mwt.getP());
}
return false;
}
}
return true;
}
use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class EncodingHelper method _extractInt32.
public static Integer _extractInt32(Object e) {
if (e instanceof Integer) {
return (Integer) e;
}
if (!(e instanceof ClassB)) {
return null;
}
ClassB cb = (ClassB) e;
String code = extractCode(cb, "@int32\n");
if (code == null) {
return null;
}
try {
return Integer.parseInt(code);
} catch (NumberFormatException nfe) {
return null;
}
}
use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class EncodingHelper method _extractBool.
public static Boolean _extractBool(Object e) {
if (e instanceof Boolean) {
return (Boolean) e;
}
if (!(e instanceof ClassB)) {
return null;
}
ClassB cb = (ClassB) e;
Object ann = cb.getDoc1().getAnnotations().get(0);
if (ann.equals("boolTrue")) {
return true;
}
if (ann.equals("boolFalse")) {
return false;
}
return null;
}
Aggregations