Пример #1
0
def get_full_name_from_visible_name(context_, globalproto):
    gpd = context_.get_visible_global(globalproto)
    if gpd is None:  # Should never happen?
        util.report_error("Bad protocol reference: " + target)
    module_ = gpd.getParent()
    modulefullname = moduledecl_get_full_name(
                         module_get_moduledecl_child(module_))
    protofullname = modulefullname + '.' + globalprotocoldecl_get_name(gpd)
    return protofullname
Пример #2
0
def get_full_name_from_visible_name(context_, globalproto):
    gpd = context_.get_visible_global(globalproto)
    if gpd is None:  # Should never happen?
        util.report_error("Bad protocol reference: " + target)
    module_ = gpd.getParent()
    modulefullname = moduledecl_get_full_name(
        module_get_moduledecl_child(module_))
    protofullname = modulefullname + '.' + globalprotocoldecl_get_name(gpd)
    return protofullname
Пример #3
0
def build_visibility(context, module_):
    fullname = moduledecl_get_full_name(module_get_moduledecl_child(module_))
    # Build visibility wrt. primary module_
    context = context.add_visible_module(fullname, module_)
    context = _get_module_members(context, fullname, module_)
    # Section 4.1.1 -- self reference of module_ by simple module_ name
    smn = util.get_simple_module_name_from_full_module_name(fullname)
    if fullname != smn:
        context = context.add_visible_module(smn, module_)
        #context = _get_module_members(context, smn, module_)
        # No: members of primary module_ are not accessible via the simple
        # name of module_

    # add on unqualified names for ``local'' module_ entities (i.e.\ for the
    # primary module_ only)
    context = _get_self_visibility(context, module_)

    # Build visibility wrt. imported modules
    context = _get_imported_modules(context, module_)
    #context = getImportedMembers(context, module_) # TODO
    return context
Пример #4
0
def build_visibility(context, module_):
    fullname = moduledecl_get_full_name(module_get_moduledecl_child(module_))
    # Build visibility wrt. primary module_
    context = context.add_visible_module(fullname, module_)
    context = _get_module_members(context, fullname, module_)
    # Section 4.1.1 -- self reference of module_ by simple module_ name
    smn = util.get_simple_module_name_from_full_module_name(fullname)
    if fullname != smn:
        context = context.add_visible_module(smn, module_)
        #context = _get_module_members(context, smn, module_)
            # No: members of primary module_ are not accessible via the simple
            # name of module_

    # add on unqualified names for ``local'' module_ entities (i.e.\ for the
    # primary module_ only)
    context = _get_self_visibility(context, module_)

    # Build visibility wrt. imported modules
    context = _get_imported_modules(context, module_)
    #context = getImportedMembers(context, module_) # TODO
    return context
Пример #5
0
def _add_module_and_get_dependencies(context_, filepath, current):
    # Section 4.2 -- Simple moduledecl name and filename of module
    #
    # Move to well-formedness? (Currently also checked for well-formed
    # moduledecl, but commenting this line here causes some problems for
    # mutually recursive imports -- should debug this)
    moduledecl_ = module_get_moduledecl_child(current)
    moduledecl_check_file_name(filepath, moduledecl_)
    fmn = moduledecl_get_full_name(moduledecl_)

    context_ = context_.add_source(fmn, filepath)
    # Make a combined add_source and add_module method for Context? (And move the
    # above name check into there)
    context_ = context_.add_module(fmn, current)
    #context_ = _add_all_members(context_, fmn, current)
        # Done later by memberloader

    importmodules = module_get_importmodule_children(current)
    for i in importmodules:
        fmn = importmodule_get_full_module_name(i)
        # sources and modules keys should match
        if fmn not in context_.get_modules().keys():
            tmp = util.convert_full_module_name_to_filepath(fmn)
            filepath = util.search_importpath_for_file(context_.import_path,
                                                       tmp)
            module_ = util.load_file_and_parse_module(filepath)
            #  # We found a parseable Scribble module at that file path -- but
            #  module decl not checked yet (checked by well-formedness, along
            #  with other well-formedness conditions) We found a parseable
            #  Scribble module at that file path -- but module decl not checked
            #  yet (checked by well-formedness, along with other well-formedness
            #  conditions)
            context_ = _add_module_and_get_dependencies(context_,
                                                        filepath,
                                                        module_)
    """importmembers = module.module_get_importmember_children(current)  # TODO: member imports"""

    return context_
Пример #6
0
def _add_module_and_get_dependencies(context_, filepath, current):
    # Section 4.2 -- Simple moduledecl name and filename of module
    #
    # Move to well-formedness? (Currently also checked for well-formed
    # moduledecl, but commenting this line here causes some problems for
    # mutually recursive imports -- should debug this)
    moduledecl_ = module_get_moduledecl_child(current)
    moduledecl_check_file_name(filepath, moduledecl_)
    fmn = moduledecl_get_full_name(moduledecl_)

    context_ = context_.add_source(fmn, filepath)
    # Make a combined add_source and add_module method for Context? (And move the
    # above name check into there)
    context_ = context_.add_module(fmn, current)
    #context_ = _add_all_members(context_, fmn, current)
    # Done later by memberloader

    importmodules = module_get_importmodule_children(current)
    for i in importmodules:
        fmn = importmodule_get_full_module_name(i)
        # sources and modules keys should match
        if fmn not in context_.get_modules().keys():
            tmp = util.convert_full_module_name_to_filepath(fmn)
            filepath = util.search_importpath_for_file(context_.import_path,
                                                       tmp)
            module_ = util.load_file_and_parse_module(filepath)
            #  # We found a parseable Scribble module at that file path -- but
            #  module decl not checked yet (checked by well-formedness, along
            #  with other well-formedness conditions) We found a parseable
            #  Scribble module at that file path -- but module decl not checked
            #  yet (checked by well-formedness, along with other well-formedness
            #  conditions)
            context_ = _add_module_and_get_dependencies(
                context_, filepath, module_)
    """importmembers = module.module_get_importmember_children(current)  # TODO: member imports"""

    return context_
Пример #7
0
def check_wellformedness_visit(checker, node_):
    context_ = checker.get_context()
    visited = context_visitor_visit(checker, node_)
    scope = get_scope(visited)
    target = get_target(visited)
    argmap = None  # Map from parameter name (String) to argument
    # (messagesignature node_)

    rolemap = None  # Map from role parameter name (String) to role argument name
    # (String) not uniform with argmap

    # Section 4.6.10 -- Well-formed argument-list
    arglist = get_argumentlist_child(visited)
    argmap = argumentlist_check_wellformedness(checker, target, arglist)

    # Section 4.6.10 -- Well-formed role-decl-list
    #roleinstantiations = roleinstantiationlist.get_roleinstantiation_children(get_roleinstantiationlist_child(node_))
    roleinstantiations = get_roleinstantiationlist_child(visited)
    rolemap = roleinstantiationlist_check_wellformedness(
        context_, target, roleinstantiations)

    ##
    # Section 4.6.10 -- "well-formedness conditions imposed by context_ myust be
    # respected by the target protocol definition" -- currently not specified
    # very precisely in langref
    #
    # Scope prefix is applied to operators (globalmessagetransfer) and recursion
    # labels (Context, globalrecursion, globalcontinue)  -- and others?
    #
    # However, substitution and visit are still needed for checking e.g. choice
    # branch role mergability
    gpd = context_.get_visible_global(target)
    module_ = gpd.getParent()
    modulefullname = moduledecl_get_full_name(
        module_get_moduledecl_child(module_))
    protofullname = modulefullname + '.' + \
            globalprotocoldecl_get_name(gpd)
    # Same as in get_target_full_name, but we also need the above bits
    # later as well as the name

    do_stack = context_.peek_do_chain()
    if protofullname not in do_stack.keys():  # Factor out
        #{
        clone = context_.clone()
        # Gets fully qualified names of all visible entities
        clone = build_visibility(clone, module_)
        # In a regular pass, set by visiting moduledecl
        clone = clone.set_current_module(modulefullname)
        # Not being done in enter because this push is for visiting the child
        # (i.e. the do target protocol), not this do statement itself
        clone = clone.push_globaldo(visited)

        tmp = globalprotocoldecl_get_child(gpd)
        if util.get_node_type(tmp) != constants.GLOBAL_PROTOCOL_DEF_NODE_TYPE:
            # TODO: could be GlobalProtocolInstance
            raise RuntimeError("TODO: " + util.get_node_type(tmp))
        block = globalprotocoldef_get_block_child(tmp)

        substitutor = NameSubstitutor(rolemap, argmap)
        substituted = substitutor.substituteNames(block)

        checker.set_context(clone)
        # is it better to just make a new WellformednessChecker?
        checker.check_wellformedness(substituted)  # discarding the return
        new_context = checker.get_context()
        new_context = new_context.pop_globaldo(visited)
        checker.set_context(new_context)
    #}
    return visited
Пример #8
0
def check_wellformedness_visit(checker, node_):
    context_ = checker.get_context()
    visited = context_visitor_visit(checker, node_)
    scope = get_scope(visited)
    target = get_target(visited)
    argmap = None # Map from parameter name (String) to argument
                  # (messagesignature node_)

    rolemap = None # Map from role parameter name (String) to role argument name
                   # (String) not uniform with argmap

    # Section 4.6.10 -- Well-formed argument-list
    arglist = get_argumentlist_child(visited)
    argmap = argumentlist_check_wellformedness(checker, target, arglist)

    # Section 4.6.10 -- Well-formed role-decl-list
    #roleinstantiations = roleinstantiationlist.get_roleinstantiation_children(get_roleinstantiationlist_child(node_))
    roleinstantiations = get_roleinstantiationlist_child(visited)
    rolemap = roleinstantiationlist_check_wellformedness(context_,
                                                         target,
                                                         roleinstantiations)

    ##
    # Section 4.6.10 -- "well-formedness conditions imposed by context_ myust be
    # respected by the target protocol definition" -- currently not specified
    # very precisely in langref
    #
    # Scope prefix is applied to operators (globalmessagetransfer) and recursion
    # labels (Context, globalrecursion, globalcontinue)  -- and others?
    #
    # However, substitution and visit are still needed for checking e.g. choice
    # branch role mergability
    gpd = context_.get_visible_global(target)
    module_ = gpd.getParent()
    modulefullname = moduledecl_get_full_name(module_get_moduledecl_child(module_))
    protofullname = modulefullname + '.' + \
            globalprotocoldecl_get_name(gpd)
        # Same as in get_target_full_name, but we also need the above bits
        # later as well as the name

    #do_frame = context_.peek_do_chain()
    
    roles = get_argument_roles(node_)
    args = get_argument_args(node_)
    #if protofullname not in do_frame.keys():  # Factor out

    new_context = context_
    if not context_.do_instance_in_chain(protofullname, roles, args):
    #{
        clone = context_.clone()
    
        # Gets fully qualified names of all visible entities
        clone = build_visibility(clone, module_) 
            # But not pure? i.e. adds on top of existing?
        # In a regular pass, set by visiting moduledecl
        clone = clone.set_current_module(modulefullname) 
        # Not being done in enter because this push is for visiting the child
        # (i.e. the do target protocol), not this do statement itself
        clone = clone.push_globaldo(visited) 

        tmp = globalprotocoldecl_get_child(gpd)
        if util.get_node_type(tmp) != constants.GLOBAL_PROTOCOL_DEF_NODE_TYPE:
            # TODO: could be GlobalProtocolInstance
            raise RuntimeError("TODO: " + util.get_node_type(tmp))
        block = globalprotocoldef_get_block_child(tmp)

        substitutor = NameSubstitutor(rolemap, argmap)
        substituted = substitutor.substituteNames(block)

        checker.set_context(clone)
            # is it better to just make a new WellformednessChecker?
        checker.check_wellformedness(substituted)  # discarding the return

        new_context = checker.get_context()
        new_context = new_context.pop_globaldo(visited)
    #}
    checker.set_context(new_context)
    return visited
Пример #9
0
def get_full_name(node_):
    moduledecl_ = module_get_moduledecl_child(node_.getParent())
    fmn = moduledecl_get_full_name(moduledecl_)
    proto = get_name(node_)
    return fmn + '.' + proto
def get_full_name(node_):
    moduledecl_ = module_get_moduledecl_child(node_.getParent())
    fmn = moduledecl_get_full_name(moduledecl_)
    proto = get_name(node_)
    return fmn + '.' + proto