Beispiel #1
0
def typecheck(ast):
    """ Check the type of the ast recursively.
    """
    metakinds = infos.semantics.metakinds  # @UndefinedVariable
    kind_dicts = infos.semantics.kind_dicts  # @UndefinedVariable

    def on_ast_nodes(visitor, node, expected):
        if _is_typed(node):
            return #Already visited, because of force visitation
        mk = metakinds[node._kind]
        if mk == 'class':
            for field in node._children:
                visitor.visit(node[field], kind_dicts[node._kind][field])
        _type_term(node, mk, expected)

    def on_ast_leafs(visitor, leaf, expected):
        if leaf and _is_typed(leaf):
            _check_kind(leaf, expected)
            return #Already typed and visited, because of force visitation
        #### force visitation to enable recursives types...
        if isinstance(leaf, Ident) and _is_current_module(leaf._node): #TODO 5: use follow_modlocal_links
            visitor.visit(leaf._node, expected)
        if isinstance(leaf, Alias):
            target = leaf._is_alias_of
            if _is_current_module(target):
                visitor.visit(target, expected)
        #### end of forcing the recursivity
        if leaf:
            _type_term(leaf, metakinds[leaf._kind], expected)

    checker = AstVisitor(default=on_ast_nodes, onleaf=on_ast_leafs, kind='bf')
    checker.node_bf(ast, list(metakinds))
    _type_term(ast, 'ast', ['_ast'])
Beispiel #2
0
def do_pass(ast):

    d = {
        'namespace': ast._name,
        'package_name': qn.package_ast(ast),
        'ast': qn.cmake_ast(ast),
        'ast_fun': qn.c_astfun(ast),
        'user_src_folder': user_src_path,
        'module_sources': '',
        'module_includes': '',
        'module_libs': '',
        'module_find_libs': ''
    }

    # Generate the package file
    build_deps = ['radl_lib']
    for p in infos.loaded_modules:
        build_deps.append(qn.package_ast(p))

    d['ast_deps'] = ' '.join(build_deps)

    astfolder = ws_path(d['package_name'])

    # Generate the ast files
    c_filename, c_file, h_filename, h_file = ASTdump.gen(ast)
    d['ast_c_filename'] = c_filename
    d['ast_h_filename'] = h_filename
    write_file(astfolder / c_filename, c_file)
    write_file(astfolder / 'include' / h_filename, h_file)

    clear(d, cmake_templates)
    clear(d, lib_static_templates_cmake_sublevel)
    clear(d, lib_cmake_templates_cmake_sublevel)

    visitor = AstVisitor(
        fun_dict_of((module_settings, static_library, cmake_library)),
        onleaf=follow_modlocal_links(AstVisitor.leaf_bf),  # @UndefinedVariable
        kind='bf')
    # We follow links to have correct dependencies, but we need unicity
    d['_seen'] = set()

    visitor.node_bf(ast, d)  #visitor follow links and unique passage

    app(d, cmake_templates)

    # Generate the cmake file
    cmake = d['cmakelists']
    cmake_file = astfolder / 'CMakeLists.txt'
    write_file(cmake_file, cmake)

    catkin_pkg.gen(astfolder, d['package_name'], build_deps, [])

    user_src = astfolder / d['user_src_folder']
    link_path(user_src, infos.module_base_path, relative=infos.relative_links)