예제 #1
0
def run_pipeline_gbq(pipeline, client, query):
    query_job = client.query(query)
    results = query_job.result()
    parameters = []
    for row in results:
        items = dict(row.items())
        parameters.append(items)

    run_pipeline(pipeline, parameters)
예제 #2
0
def test():
    text = """
            class B inherits A { 
                a : String ;
                b : AUTO_TYPE ;
            };
            class A inherits B { } ;
            """

    print("corriendo")
    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)
    print(errors)
    assert errors == [
        "B is involved in a cyclic heritage",
        "A class Main with a method main most be provided",
    ]
def test():
    text = """
       class A { 
           a : String ;
           b : Bool ;
           c : Int <- 0 ;
           d : Object <- while c < 1 loop c = c + 1 pool  ;
       } ;
       class Point {
            step ( p : AUTO_TYPE ) : AUTO_TYPE { p . translate ( 1 , 1 ) } ;
            main ( ) : Object {
                let p : AUTO_TYPE <- new Point in {
                    step ( p ) ; (*Puede lanzar error semantico*)
                } 
            } ;
        } ;
        """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    print("Errors:", errors)
    print("Context:")
    print(context)

    assert errors == ["A class Main with a method main most be provided"]
예제 #4
0
def test():
    text = """
       class Point {
            x : AUTO_TYPE ;
            y : AUTO_TYPE ;
            init ( n : Int , m : Int ) : SELF_TYPE {
            {
                x <- n ;
                y <- m ;
            } } ;
        } ;
        """

    ast = run_pipeline(text)

    formatter = FormatVisitor()
    tree = formatter.visit(ast)

    tree = tree.replace("\t", "")
    tree = tree.replace("\n", "")
    tree = tree.replace("\\", "")

    assert (
        tree ==
        "__ProgramNode [<class> ... <class>]__ClassDeclarationNode: class Point  { <feature> ... <feature> }__AttrDeclarationNode: x : AUTO_TYPE <- <exp>__NONE__AttrDeclarationNode: y : AUTO_TYPE <- <exp>__NONE__FuncDeclarationNode: init(n:Int, m:Int) : SELF_TYPE { <body> }__BlockNode: {<exp>; ... <exp>;}__AssignNode: x <- <expr>__ VariableNode: n__AssignNode: y <- <expr>__ VariableNode: m"
    )
def test():
    text = """
        class A inherits B { };
        class B inherits A { 
            f ( ) : Int {
                g()
            } ;
        } ;
        """

    print("corriendo")
    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    if errors != [
            "A is involved in a cyclic heritage",
            "A class Main with a method main most be provided",
            'Method "g" is not defined in B.',
    ]:
        print(errors)
        assert False

    assert True
예제 #6
0
def test():
    text = """
       class A { } ;
       class Point {
            step ( p : AUTO_TYPE ) : AUTO_TYPE { p . translate ( 1 , 1 ) } ;
            main ( ) : Object {
                let p : AUTO_TYPE <- new Point in {
                    step ( p ) ; (*Puede lanzar error semantico*)
                } 
            } ;
        } ;
        """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    # context = collector.context

    # print("Errors:", errors)
    # print("Context:")
    # print(context)

    assert errors == []
예제 #7
0
def test():
    text = """
        class Cons inherits List {
        xcar : Int ;
        xcdr : List ;

        isNill ( ) : Bool {
                false
        } ;

        init ( hd : Int , tl : List ) : Cons {
                {
                xcar <- hd ;
                xcdr <- tl ;
                self ;
                }
        } ;
        } ;
        """

    ast = run_pipeline(text)

    formatter = FormatVisitor()
    tree = formatter.visit(ast)

    tree = tree.replace("\t", "")
    tree = tree.replace("\n", "")
    tree = tree.replace("\\", "")

    assert (
        tree
        == "__ProgramNode [<class> ... <class>]__ClassDeclarationNode: class Cons inherits List { <feature> ... <feature> }__AttrDeclarationNode: xcar : Int <- <exp>__NONE__AttrDeclarationNode: xcdr : List <- <exp>__NONE__FuncDeclarationNode: isNill() : Bool { <body> }__ BooleanNode: false__FuncDeclarationNode: init(hd:Int, tl:List) : Cons { <body> }__BlockNode: {<exp>; ... <exp>;}__AssignNode: xcar <- <expr>__ VariableNode: hd__AssignNode: xcdr <- <expr>__ VariableNode: tl__ VariableNode: self"
    )
def test():
    text = """
       class Main inherits IO {
            main ( ) : AUTO_TYPE {
                let x : AUTO_TYPE <- 3 + 2 in {
                    case x of
                        y : Int => out_string ( " Ok " ) ;
                    esac ;
                }
            } ;
        } ;
        """

    ast = run_pipeline(text)

    formatter = FormatVisitor()
    tree = formatter.visit(ast)

    tree = tree.replace("\t", "")
    tree = tree.replace("\n", "")
    tree = tree.replace("\\", "")

    assert (
        tree ==
        "__ProgramNode [<class> ... <class>]__ClassDeclarationNode: class Main inherits IO { <feature> ... <feature> }__FuncDeclarationNode: main() : AUTO_TYPE { <body> }__LetNode: let <identif-list> in <expr>__VarDeclarationNode: x : AUTO_TYPE <- <expr>__<expr> PlusNode <expr>__ ConstantNumNode: 3__ ConstantNumNode: 2__BlockNode: {<exp>; ... <exp>;}__CaseNode: case <expr> of <case_block> esac__ VariableNode: x__CaseItemNode: y : Int => <exp>;__CallNode: out_string(<expr>, ..., <expr>)__ StringNode:  Ok "
    )
def test():
    text = """
       class Point {
            step ( p : AUTO_TYPE ) : AUTO_TYPE { p . translate ( 1 , 1 ) } ;
            main ( ) : Object {
                let p : AUTO_TYPE <- new Point in {
                    step ( p ) ; (*Puede lanzar error semantico*)
                } 
            } ;
        } ;
        """

    ast = run_pipeline(text)

    formatter = FormatVisitor()
    tree = formatter.visit(ast)

    tree = tree.replace("\t", "")
    tree = tree.replace("\n", "")
    tree = tree.replace("\\", "")

    assert (
        tree ==
        "__ProgramNode [<class> ... <class>]__ClassDeclarationNode: class Point  { <feature> ... <feature> }__FuncDeclarationNode: step(p:AUTO_TYPE) : AUTO_TYPE { <body> }__CallNode: <obj>.translate(<expr>, ..., <expr>)__ VariableNode: p__ ConstantNumNode: 1__ ConstantNumNode: 1__FuncDeclarationNode: main() : Object { <body> }__LetNode: let <identif-list> in <expr>__VarDeclarationNode: p : AUTO_TYPE <- <expr>__ InstantiateNode: new Point()__BlockNode: {<exp>; ... <exp>;}__CallNode: step(<expr>, ..., <expr>)__ VariableNode: p"
    )
예제 #10
0
def test():
    text = """
        
       class A { 
           a : String ;
        } ;
         class Point inherits A {
            f ( a : AUTO_TYPE , b : AUTO_TYPE ) : AUTO_TYPE {
                if ( a = 1 ) then b else
                    g ( a + 1 , b / 2 )
                fi
            } ;
            g ( a : AUTO_TYPE , b : AUTO_TYPE ) : AUTO_TYPE {
                if ( b = 1 ) then a else
                    f ( a / 2 , b + 1 ) 
                fi
            } ;
        } ;
        
        """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    __ = checker.visit(ast, None)

    tset_builder = TSetBuilder(context, errors)
    tset = tset_builder.visit(ast, None)

    tset_reducer = TSetReducer(context, errors)
    reduced_set = tset_reducer.visit(ast, tset)

    print("Errors:", errors)
    print("Context:")
    print(context)
    print(reduced_set)

    assert errors == ["A class Main with a method main most be provided"]
예제 #11
0
def test():

    text = """
   
     class B inherits Point {
                x : String ;
                init ( n : String , z : Int , z : Int) : Bool {
                {
                    n <- "ok" ;
                    z <- 1 + 3 ;
                } } ;
            } ;
        class Point {
                x : AUTO_TYPE ;
                y : AUTO_TYPE ;
                init ( n : Int , m : Int ) : Int {
                {
                    x <- n ;
                    y <- m ;
                } } ;
            } ;
       
            """

    print("corriendo")
    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    assert errors == [
        'Attribute "x" is already defined in B.',
        "A class Main with a method main most be provided",
        "More tan one param in method init has the name z",
        'Cannot convert "Int" into "Bool".',
        'Method "init" already defined in "an ancestor of B" with a different signature.',
    ]
예제 #12
0
def test():
    text = """
            class Main inherits Point {
                x : String ;
                init ( n : String , m : Int) : Int {
                {
                    n <- "Testing main" ;
                    m <- 1 + 2 ;
                } } ;

                main ( n : String , m : Int ) : Int {
                {
                    n <- "Buen dia" ;
                    m <- 3 ;
                } } ;
            } ;
        class Point {
                x : AUTO_TYPE ;
                y : AUTO_TYPE ;
                init ( n : String , m : Int ) : Int {
                {
                    x <- n ;
                    y <- m ;
                } } ;
            } ;
            """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    assert errors == [
        'Attribute "x" is already defined in Main.',
        '"main" method in class Main does not receive any parameters',
    ]
예제 #13
0
def test():
    text = """
        
       class A { 
           a : String ;
        } ;
         class Point inherits A {
            ackermann ( m : AUTO_TYPE , n : AUTO_TYPE ) : AUTO_TYPE {
                if  m < 0  then 1 else
                    if  n < 0  then ackermann ( m - 1 , 1 ) else
                        ackermann ( m - 1 , ackermann ( m , n - 1 ) )
                    fi
                fi
            } ;

        } ;
        
        """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    __ = checker.visit(ast, None)

    tset_builder = TSetBuilder(context, errors)
    tset = tset_builder.visit(ast, None)

    tset_reducer = TSetReducer(context, errors)
    reduced_set = tset_reducer.visit(ast, tset)

    print("Errors:", errors)
    print("Context:")
    print(context)
    print(reduced_set)

    assert errors == ["A class Main with a method main most be provided"]
예제 #14
0
def test():
    text = """
            class Main inherits Point {
                x : String ;
                init ( n : String , m : Int) : Int {
                {
                    n <- "Testing main" ;
                    m <- 1 + 2 ;
                } } ;
            } ;
        class Point {
                x : AUTO_TYPE ;
                y : AUTO_TYPE ;
                init ( n : String , m : Int ) : Int {
                {
                    x <- n ;
                    y <- m ;
                } } ;
                main ( n : String , m : Int ) : Int {
                {
                    x <- n ;
                    y <- m ;
                } } ;
            } ;
            """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    assert errors == [
        'Attribute "x" is already defined in Main.',
        "A class Main with a method main most be provided",
    ]
def test():
    text = """
       class Point {
           succ ( n : Int ) : AUTO_TYPE { n + 1 } ;
        } ;
        """

    ast = run_pipeline(text)

    formatter = FormatVisitor()
    tree = formatter.visit(ast)

    tree = tree.replace("\t", "")
    tree = tree.replace("\n", "")
    tree = tree.replace("\\", "")

    assert (
        tree ==
        "__ProgramNode [<class> ... <class>]__ClassDeclarationNode: class Point  { <feature> ... <feature> }__FuncDeclarationNode: succ(n:Int) : AUTO_TYPE { <body> }__<expr> PlusNode <expr>__ VariableNode: n__ ConstantNumNode: 1"
    )
예제 #16
0
def test():
    text = """
            class C inherits J { } ;
            class A inherits B { } ;
            class B inherits A { } ;
            class C { } ;
            class D inherits E { } ;
            class E inherits F { } ;
            class F inherits D { } ;
            class G inherits F { } ;
           """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    err = [
        "Type with the same name (C) already in context.",
        'Type "J" is not defined.',
        "Parent type is already set for C.",
        "A is involved in a cyclic heritage",
        "D is involved in a cyclic heritage",
        "A class Main with a method main most be provided",
    ]

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    if errors != err:
        print(errors)
        assert False

    assert True
예제 #17
0
def main():
    """
    Runs pipeline from the nwb file
    Usage:
    python pipeline_from_nwb_file.py INPUT_NWB_FILE

    User must specify the OUTPUT_DIR

    """

    input_nwb_file = sys.argv[1]
    input_nwb_file_basename = os.path.basename(input_nwb_file)
    cell_name = os.path.splitext(input_nwb_file_basename)[0]

    cell_dir = os.path.join(OUTPUT_DIR, cell_name)

    if not os.path.exists(cell_dir):
        os.makedirs(cell_dir)

    lu.configure_logger(cell_dir)

    pipe_input = gpi.generate_pipeline_input(cell_dir,
                                             input_nwb_file=input_nwb_file)

    input_json = os.path.join(cell_dir, INPUT_JSON)
    ju.write(input_json, pipe_input)

    #   reading back from disk
    pipe_input = ju.read(input_json)
    pipe_output = run_pipeline(pipe_input["input_nwb_file"],
                               pipe_input.get("input_h5_file", None),
                               pipe_input["output_nwb_file"],
                               pipe_input.get("stimulus_ontology_file", None),
                               pipe_input.get("qc_fig_dir",
                                              None), pipe_input["qc_criteria"],
                               pipe_input["manual_sweep_states"])

    ju.write(os.path.join(cell_dir, OUTPUT_JSON), pipe_output)
예제 #18
0
def test():
    text = """
       class A {
        b : AUTO_TYPE ;
        a : AUTO_TYPE ;

        f ( ) : Int { {
            let x : AUTO_TYPE <- a + b in x ;
        } };
    };
        """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    if errors != ["A class Main with a method main most be provided"]:
        print(errors)
        assert False

    tset_builder = TSetBuilder(context, errors)
    tset = tset_builder.visit(ast, None)

    tset_reducer = TSetReducer(context, errors)
    reduced_set = tset_reducer.visit(ast, tset)

    tset_merger = TSetMerger(context, errors)
    tset_merger.visit(ast, reduced_set)

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    formatter = FormatVisitor()
    tree = formatter.visit(ast)

    print("Errors:", errors)
    print("Context:")
    print(context)
    print(reduced_set)
    print(tree)

    assert errors == [
        "A class Main with a method main most be provided",
        "A class Main with a method main most be provided",
    ]
예제 #19
0
def test():
    text = """

      class Main inherits IO {
            main() : AUTO_TYPE {
                let x : AUTO_TYPE <- 3 + (let y: AUTO_TYPE <- 8 in y ) in
                case x of 
                    y: Int => out_string("ok");
                    esac
            };
        };


        """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    print(errors)
    if errors != []:
        print(errors)
        assert False

    tset_builder = TSetBuilder(context, errors)
    tset = tset_builder.visit(ast, None)

    tset_reducer = TSetReducer(context, errors)
    reduced_set = tset_reducer.visit(ast, tset)

    tset_merger = TSetMerger(context, errors)
    tset_merger.visit(ast, reduced_set)

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    formatter = FormatVisitor()
    tree = formatter.visit(ast)

    print("Errors:", errors)
    print("Context:")
    print(context)
    print(reduced_set)
    print(tree)

    assert errors == []
예제 #20
0
def test():
    text = """

      class Main {
    main (): Object {
        0
    };
};

class Ackermann {
    ackermann(m: AUTO_TYPE, n: AUTO_TYPE): AUTO_TYPE {
        if m = 0 then n + 1 else
            if n = 0 then ackermann(m - 1, 1) else
                ackermann(m - 1, ackermann(m, n - 1))
            fi
        fi
    };
};

        """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    print(errors)
    if errors != []:
        print(errors)
        assert False

    tset_builder = TSetBuilder(context, errors)
    tset = tset_builder.visit(ast, None)

    tset_reducer = TSetReducer(context, errors)
    reduced_set = tset_reducer.visit(ast, tset)

    tset_merger = TSetMerger(context, errors)
    tset_merger.visit(ast, reduced_set)

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    formatter = FormatVisitor()
    tree = formatter.visit(ast)

    print("Errors:", errors)
    print("Context:")
    print(context)
    print(reduced_set)
    print(tree)

    assert errors == []
예제 #21
0
def test():
    text = """

     class Main {
    main (): Object {
        0
    };

    f(a: AUTO_TYPE, b: AUTO_TYPE): AUTO_TYPE {
        if a = 1 then b else
            g(a + 1, b / 1)
        fi
    };

    g(a: AUTO_TYPE, b: AUTO_TYPE): AUTO_TYPE {
        if b = 1 then a else
            f(a / 2, b + 1)
        fi
    };
};
        """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    print(errors)
    if errors != []:
        print(errors)
        assert False

    tset_builder = TSetBuilder(context, errors)
    tset = tset_builder.visit(ast, None)

    tset_reducer = TSetReducer(context, errors)
    reduced_set = tset_reducer.visit(ast, tset)

    tset_merger = TSetMerger(context, errors)
    tset_merger.visit(ast, reduced_set)

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    formatter = FormatVisitor()
    tree = formatter.visit(ast)

    print("Errors:", errors)
    print("Context:")
    print(context)
    print(reduced_set)
    print(tree)

    assert errors == []
def test():
    text = """
        
       class A { 
           a : String ;
           b : AUTO_TYPE ;
           c : AUTO_TYPE <- 0 ;
           d : Object <- while c loop c + 1 pool  ;
           j : AUTO_TYPE ;
           l : AUTO_TYPE ;
           fact ( n : AUTO_TYPE ) : AUTO_TYPE { if  n < 0  then 1 else  n + fact ( n - 1 )   fi } ;
           step ( p : AUTO_TYPE ) : AUTO_TYPE {
               b <-
                {
                    p + 5 ;
                    j <- p ;
                    p <- false ;
                    isvoid d ;

                    
                    l @ Point . main ( ) ;
                } 
            } ;
        } ;
         class Point inherits A {
            h : AUTO_TYPE <- "debe ser tipo string" ;
            k : AUTO_TYPE ;
            main ( ) : AUTO_TYPE {
                let i : AUTO_TYPE <- new A in {
                    isvoid i ; (*Puede lanzar error semantico*)
                }
            } ;
            ackermann ( m : AUTO_TYPE , n : AUTO_TYPE ) : AUTO_TYPE {
                if  m < 0  then 1 else
                    if  n < 0  then ackermann ( m - 1 , 1 ) else
                        ackermann ( m - 1 , ackermann ( m , n - 1 ) )
                    fi
                fi
            } ;
        } ;
        
        """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    __ = checker.visit(ast, None)

    tset_builder = TSetBuilder(context, errors)
    tset = tset_builder.visit(ast, None)

    tset_reducer = TSetReducer(context, errors)
    reduced_set = tset_reducer.visit(ast, tset)

    print("Errors:", errors)
    print("Context:")
    print(context)
    print(reduced_set)

    assert errors == ["A class Main with a method main most be provided"]
예제 #23
0
def test():
    text = """

       class Main {
        a : AUTO_TYPE<- "Hola";
        main ( ) : Int { {
            case {let i: AUTO_TYPE <- 12 in {let i: AUTO_TYPE <- "Hola" in {"Hi";
                case 12 of
                    x : Int => x;
                    y : AUTO_TYPE => y;
                    z: String => let i : AUTO_TYPE in {
                       i<- case self of
                            x: Int => 12;
                            x: AUTO_TYPE => if 12<12 then x else "Hola" fi ;
                        esac
                    ;};
                esac
            ;};};} of
                x : Int => 12;
                y : AUTO_TYPE => let i: AUTO_TYPE <- y in y ;
            esac ;
        a.length();} } ;
    } ;

        """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    # print(errors)
    # if errors != []:
    #     print(errors)
    #     assert False

    tset_builder = TSetBuilder(context, errors)
    tset = tset_builder.visit(ast, None)

    tset_reducer = TSetReducer(context, errors)
    reduced_set = tset_reducer.visit(ast, tset)

    tset_merger = TSetMerger(context, errors)
    tset_merger.visit(ast, reduced_set)

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    formatter = FormatVisitor()
    tree = formatter.visit(ast)

    # print("Errors:", errors)
    # print("Context:")
    # print(context)
    # print(reduced_set)
    # print(tree)

    final_tree = """__ProgramNode [<class> ... <class>]__ClassDeclarationNode: class Main  { <feature> ... <feature> }__AttrDeclarationNode: a : String <- <exp>__ StringNode: Hola__FuncDeclarationNode: main() : Int { <body> }__BlockNode: {<exp>; ... <exp>;}__CaseNode: case <expr> of <case_block> esac__BlockNode: {<exp>; ... <exp>;}__LetNode: let <identif-list> in <expr>__VarDeclarationNode: i : Int <- <expr>__ ConstantNumNode: 12__BlockNode: {<exp>; ... <exp>;}__LetNode: let <identif-list> in <expr>__VarDeclarationNode: i : String <- <expr>__ StringNode: Hola__BlockNode: {<exp>; ... <exp>;}__ StringNode: Hi__CaseNode: case <expr> of <case_block> esac__ ConstantNumNode: 12__CaseItemNode: x : Int => <exp>;__ VariableNode: x__CaseItemNode: y : Object => <exp>;__ VariableNode: y__CaseItemNode: z : String => <exp>;__LetNode: let <identif-list> in <expr>__VarDeclarationNode: i : Object <- <expr>__NONE__BlockNode: {<exp>; ... <exp>;}__AssignNode: i <- <expr>__CaseNode: case <expr> of <case_block> esac__ VariableNode: self__CaseItemNode: x : Int => <exp>;__ ConstantNumNode: 12__CaseItemNode: x : Object => <exp>;__IfNode: if <expr> then <expr> else <exp> fi__<expr> LessNode <expr>__ ConstantNumNode: 12__ ConstantNumNode: 12__ VariableNode: x__ StringNode: Hola__CaseItemNode: x : Int => <exp>;__ ConstantNumNode: 12__CaseItemNode: y : Object => <exp>;__LetNode: let <identif-list> in <expr>__VarDeclarationNode: i : Object <- <expr>__ VariableNode: y__ VariableNode: y__CallNode: <obj>.length(<expr>, ..., <expr>)__ VariableNode: a"""

    tree = tree.replace("\t", "")
    tree = tree.replace("\n", "")
    tree = tree.replace("\\", "")

    assert tree == final_tree
    assert errors == []
예제 #24
0
def test():
    text = """
(* This program prints the first 10 numbers of fibonacci *)
class Main {

    main(): Object {
        let total: AUTO_TYPE <- 10,
            i: AUTO_TYPE <- 1 ,
            io: AUTO_TYPE <- new IO in
                while i <= total loop {
                    io.out_int(fibonacci(i));
                    io.out_string("n");
                    i <- i + 1;
                }
                pool
    };

    fibonacci (n: AUTO_TYPE): AUTO_TYPE {
        if n <= 2 then 1 else fibonacci(n - 1) + fibonacci(n - 2) fi
    };
};        """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    print(errors)
    if errors != []:
        print(errors)
        assert False

    tset_builder = TSetBuilder(context, errors)
    tset = tset_builder.visit(ast, None)

    tset_reducer = TSetReducer(context, errors)
    reduced_set = tset_reducer.visit(ast, tset)

    tset_merger = TSetMerger(context, errors)
    tset_merger.visit(ast, reduced_set)

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    formatter = FormatVisitor()
    tree = formatter.visit(ast)

    print("Errors:", errors)
    print("Context:")
    print(context)
    print(reduced_set)
    print(tree)

    assert errors == []
예제 #25
0
def test():
    # text = """
    #         class A {
    #             f ( a : Int , d : Int ) : Int {
    #                 d <- False
    #             };
    #         };
    #         class B inherits A {
    #             f ( a : A , d : Int ) : A {
    #                 d <- True
    #             };
    #         };
    #         """

    text = """
        class Cons {
        xcar : Int ;
        xcdr : String ;

        isNill ( ) : Bool {
                false
        } ;

        init ( hd : Int , tl : String ) : AUTO_TYPE {
                {
                xcar <- hd ;
                xcdr <- tl ;
                self;
                }
        } ;
        } ;
        """

    print("corriendo")
    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    if errors != ["A class Main with a method main most be provided"]:
        print(errors)
        assert False

    tset_builder = TSetBuilder(context, errors)
    tset = tset_builder.visit(ast, None)

    tset_reducer = TSetReducer(context, errors)
    reduced_set = tset_reducer.visit(ast, tset)

    tset_merger = TSetMerger(context, errors)
    tset_merger.visit(ast, reduced_set)

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    formatter = FormatVisitor()
    tree = formatter.visit(ast)

    if errors != [
            "A class Main with a method main most be provided",
            "A class Main with a method main most be provided",
    ]:
        print("Errors:", errors)
        print("Context:")
        print(context)
        print(reduced_set)
        print(tree)
        assert False

    final_tree = """__ProgramNode [<class> ... <class>]__ClassDeclarationNode: class Cons  { <feature> ... <feature> }__AttrDeclarationNode: xcar : Int <- <exp>__NONE__AttrDeclarationNode: xcdr : String <- <exp>__NONE__FuncDeclarationNode: isNill() : Bool { <body> }__ BooleanNode: false__FuncDeclarationNode: init(hd:Int, tl:String) : Cons { <body> }__BlockNode: {<exp>; ... <exp>;}__AssignNode: xcar <- <expr>__ VariableNode: hd__AssignNode: xcdr <- <expr>__ VariableNode: tl__ VariableNode: self"""
    tree = tree.replace("\t", "")
    tree = tree.replace("\n", "")
    tree = tree.replace("\\", "")

    print(tree)
    assert tree == final_tree
예제 #26
0
def test():
    text = """
class Main {
    main(a : AUTO_TYPE) : AUTO_TYPE {
        let x : AUTO_TYPE <- 3 in
            case x of
                y : IO => y.out_string(a);
            esac
    };
};
        """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    if errors != [
            '"main" method in class Main does not receive any parameters',
    ]:
        print(errors)
        assert False

    tset_builder = TSetBuilder(context, errors)
    tset = tset_builder.visit(ast, None)

    tset_reducer = TSetReducer(context, errors)
    reduced_set = tset_reducer.visit(ast, tset)

    tset_merger = TSetMerger(context, errors)
    tset_merger.visit(ast, reduced_set)

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    formatter = FormatVisitor()
    tree = formatter.visit(ast)

    print("Errors:", errors)
    print("Context:")
    print(context)
    print(reduced_set)
    print(tree)

    assert errors == [
        '"main" method in class Main does not receive any parameters',
        '"main" method in class Main does not receive any parameters',
    ]
def test():
    text = """

       class A {
           a : String ;
           b : AUTO_TYPE ;
           c : AUTO_TYPE <- 0 ;
           d : Object <- while c loop c + 1 pool  ; (*first and second errors*)
           j : AUTO_TYPE ;
           l : AUTO_TYPE ;
           fact ( n : AUTO_TYPE ) : AUTO_TYPE { if  n < 0  then 1 else  n + fact ( n - 1 )   fi } ;
           step ( p : AUTO_TYPE ) : AUTO_TYPE {
               b <-
                {
                    p + 5 ;
                    j <- p ; (*third error*)
                    p <- false ;
                    isvoid d ;

                    l @ Point . main ( ) ;
                    l.main();
                }
            } ;
        } ;
         class Point inherits A {
            h : AUTO_TYPE <- "debe ser tipo string" ;
            k : AUTO_TYPE ;
            main ( ) : AUTO_TYPE {
                let i : AUTO_TYPE <- new A in {
                    isvoid i ; (*Puede lanzar error semantico*)
                }
            } ;
            ackermann ( m : AUTO_TYPE , n : AUTO_TYPE ) : AUTO_TYPE {
                if  m < 0  then 1 else
                    if  n < 0  then ackermann ( m - 1 , 1 ) else
                        ackermann ( m - 1 , ackermann ( m , n - 1 ) )
                    fi
                fi
            } ;
        } ;

        """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    if errors != ["A class Main with a method main most be provided"]:
        print(errors)
        assert False

    tset_builder = TSetBuilder(context, errors)
    tset = tset_builder.visit(ast, None)

    tset_reducer = TSetReducer(context, errors)
    reduced_set = tset_reducer.visit(ast, tset)

    tset_merger = TSetMerger(context, errors)
    tset_merger.visit(ast, reduced_set)

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    formatter = FormatVisitor()
    tree = formatter.visit(ast)

    print("Errors:", errors)
    print("Context:")
    print(context)
    print(reduced_set)
    print(tree)

    assert errors == [
        "A class Main with a method main most be provided",
        "A class Main with a method main most be provided",
        "Expression after 'while' must be bool, current is Object",
        'Operation is not defined between "Object" and "Int".',
        'Cannot convert "Object" into "Int".',
    ]
예제 #28
0
def test():
    text = """
class Main inherits IO {
    main(): IO {
        let vector: AUTO_TYPE <- (new Vector2).init(0, 0) in
            vector.print_vector()
    };
};

class Vector2 {
    x: AUTO_TYPE;
    y: AUTO_TYPE;

    init(x_: AUTO_TYPE, y_: AUTO_TYPE): AUTO_TYPE { {
        x <- x_;
        y <- y_;
        self;
    } };


    get_x(): AUTO_TYPE {
        x
    };

    get_y(): AUTO_TYPE {
        y
    };

    add(v: Vector2): AUTO_TYPE {
        (new Vector2).init(x + v.get_x(), y + v.get_y())
    };

    print_vector(): AUTO_TYPE {
        let io: IO <- new IO in {
            io.out_string(" ( ");
            io.out_int(get_x());
            io.out_string("; ");
            io.out_int(get_y());
            io.out_string(" ) ");
        }
    };

    clone_vector(): AUTO_TYPE {
        (new Vector2).init(x, y)
    };
};
        """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    print(errors)
    if errors != []:
        print(errors)
        assert False

    tset_builder = TSetBuilder(context, errors)
    tset = tset_builder.visit(ast, None)

    tset_reducer = TSetReducer(context, errors)
    reduced_set = tset_reducer.visit(ast, tset)

    tset_merger = TSetMerger(context, errors)
    tset_merger.visit(ast, reduced_set)

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    formatter = FormatVisitor()
    tree = formatter.visit(ast)

    print("Errors:", errors)
    print("Context:")
    print(context)
    print(reduced_set)
    print(tree)

    assert errors == []
예제 #29
0
def test():
    text = """

      class Main {
    main (): Object {
        0
    };
};

class Point {
    x: AUTO_TYPE;
    y: AUTO_TYPE;

    init(x0: Int, y0: Int): AUTO_TYPE {{
        x <- x0;
        y <- y0;
        self;
    }};
};

        """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    print(errors)
    if errors != []:
        print(errors)
        assert False

    tset_builder = TSetBuilder(context, errors)
    tset = tset_builder.visit(ast, None)

    tset_reducer = TSetReducer(context, errors)
    reduced_set = tset_reducer.visit(ast, tset)

    tset_merger = TSetMerger(context, errors)
    tset_merger.visit(ast, reduced_set)

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    formatter = FormatVisitor()
    tree = formatter.visit(ast)

    print("Errors:", errors)
    print("Context:")
    print(context)
    print(reduced_set)
    print(tree)

    assert errors == []
예제 #30
0
def test():
    text = """

      class Main {
  pp : AUTO_TYPE;
    main() : AUTO_TYPE {
        pp <- self
    };
};

        """

    ast = run_pipeline(text)
    errors = []

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    print(errors)
    if errors != []:
        print(errors)
        assert False

    tset_builder = TSetBuilder(context, errors)
    tset = tset_builder.visit(ast, None)

    tset_reducer = TSetReducer(context, errors)
    reduced_set = tset_reducer.visit(ast, tset)

    tset_merger = TSetMerger(context, errors)
    tset_merger.visit(ast, reduced_set)

    collector = TypeCollector(errors)
    collector.visit(ast)

    context = collector.context

    builder = TypeBuilder(context, errors)
    builder.visit(ast)

    checker = TypeChecker(context, errors)
    checker.visit(ast, None)

    formatter = FormatVisitor()
    tree = formatter.visit(ast)

    print("Errors:", errors)
    print("Context:")
    print(context)
    print(reduced_set)
    print(tree)

    assert errors == []