Ejemplo n.º 1
0
def _project_all(context_):
    for _, module_ in context_.get_modules().items():
        clone = context_.set_current_module(module_get_full_name(module_))
        clone = build_visibility(clone, module_)
        for (proto, gpd) in clone.get_visible_globals().items():
            full_global_name = globalprotocoldecl_get_full_name(gpd)
            rdl = globalprotocoldecl_get_roledecllist_child(gpd)
            #rolemap = roledecllist_get_rolemap(rdl) 
            #for role_ in globalprotocoldecl_get_role_names(gpd):
            for rd in roledecllist_get_roledecl_children(rdl):
                dname = roledecl_get_declaration_name(rd)
                role_ = roledecl_get_role_name(rd)
                full_local_name = globaldo_get_projected_member_name(
                                      full_global_name, role_)
                                      #full_global_name, rolemap[role_])
                if context_.has_projection(full_local_name):
                    break
                projector = Projector()
                lpd = projector.project_globalprotocoldecl(clone, gpd, dname)#, rolemap)
                #full_name = lpd.get_full_name(clone)
                context_ = context_.add_projection(full_local_name, lpd)
                
                #print "Projected", full_global_name, "for", role_ + ":\n", \
                #      lpd.pretty_print()
    return context_
Ejemplo n.º 2
0
def _check_wellformedness(context_):
    for _, module_ in context_.get_modules().items():
        clone = context_.clone()
        # Gets fully qualified names of all visible entities
        clone = build_visibility(clone, module_)
        # Takes the prepared Context (modules loaded and visibility built etc.)
        # for a target module_ and checks the well-formedness conditions that
        # must hold for each member of the dependency set (Section 4.2) on this
        # target
        checker = WellformednessChecker(clone)
        checker.check_wellformedness(module_)
Ejemplo n.º 3
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
Ejemplo n.º 4
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