Search in sources :

Example 56 with ClassB

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);
    }
}
Also used : ExpCore(ast.ExpCore) Expression(ast.Expression) Position(ast.Ast.Position) CloneVisitor(coreVisitors.CloneVisitor) ClassB(ast.ExpCore.ClassB) ClassB(ast.ExpCore.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore)

Example 57 with ClassB

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);
}
Also used : Path(ast.Ast.Path) MethodType(ast.Ast.MethodType) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ClassB(ast.ExpCore.ClassB)

Example 58 with ClassB

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;
}
Also used : From(coreVisitors.From) NestedClass(ast.ExpCore.ClassB.NestedClass) Program(programReduction.Program) Path(ast.Ast.Path) Type(ast.Ast.Type) ErrorMessage(ast.ErrorMessage) Phase(ast.ExpCore.ClassB.Phase) Assertions(tools.Assertions) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Collectors(java.util.stream.Collectors) Functions(auxiliaryGrammar.Functions) ArrayList(java.util.ArrayList) List(java.util.List) ClassB(ast.ExpCore.ClassB) Optional(java.util.Optional) Norm(programReduction.Norm) Mdf(ast.Ast.Mdf) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ClassB(ast.ExpCore.ClassB)

Example 59 with ClassB

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;
    }
}
Also used : ClassB(ast.ExpCore.ClassB)

Example 60 with ClassB

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;
}
Also used : ClassB(ast.ExpCore.ClassB)

Aggregations

ClassB (ast.ExpCore.ClassB)107 ArrayList (java.util.ArrayList)33 Path (ast.Ast.Path)30 ExpCore (ast.ExpCore)25 Member (ast.ExpCore.ClassB.Member)25 EncodingHelper.ensureExtractClassB (auxiliaryGrammar.EncodingHelper.ensureExtractClassB)20 Program (programReduction.Program)20 Ast (ast.Ast)19 MethodWithType (ast.ExpCore.ClassB.MethodWithType)19 MethodSelector (ast.Ast.MethodSelector)18 NestedClass (ast.ExpCore.ClassB.NestedClass)18 List (java.util.List)17 ActionType (platformSpecific.fakeInternet.ActionType)16 Doc (ast.Ast.Doc)12 Type (ast.Ast.Type)12 ErrorMessage (ast.ErrorMessage)12 Optional (java.util.Optional)10 C (ast.Ast.C)9 MethodType (ast.Ast.MethodType)8 Phase (ast.ExpCore.ClassB.Phase)8