コード例 #1
0
    def _traverse_globaldo(self, node_):
        node_ = super(Unfolder, self)._traverse_globaldo(node_)
        target = globaldo_get_target(self._context, node_)
        roles = globaldo_get_roles(node_)
        args = globaldo_get_args(node_)
        key = self._make_seen_protos_key(target, roles, args)
        if key not in self._seen_protos:
            self._seen_protos.add(key)
            
            # .. FIXME: do substitution .. duplicate from globaldo
            
            ris = globaldo_get_roleinstantiationlist(node_)
            args = globaldo_get_argumentlist(node_)
            
            rolemap = roleinstantiationlist_get_map(self._context, target, ris)
            argmap = argumentlist_get_map(self._context, target, args)
            
            gpd = self._context.get_visible_global(target)
            """module_ = gpd.getParent()
            modulefullname = module_get_full_name(module_)
            clone = self._context.clone()
            clone = build_visibility(clone, module_)
            clone = clone.set_current_module(modulefullname)"""
            
            body = copy.deepcopy(globalprotocoldecl_get_child(gpd))
            block = globalprotocoldef_get_block_child(body)
                    # FIXME: copy
            substitutor = NameSubstitutor(rolemap, argmap)
            substituted = substitutor.substituteNames(block)

            node_ = self.traverse(globalblock_get_interactionsequence(substituted))
            #node_ = self.traverse(block)
            self._seen_protos.remove(key)
        return node_
コード例 #2
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
コード例 #3
0
ファイル: globaldo.py プロジェクト: rhu1/scribble-python
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