コード例 #1
0
def project(projector, node_):
    context_ = projector.context
    rolearg = projector.role
    scope = get_scope(node_)
    target = get_target_full_name(context_, node_)
    gpd = context_.get_visible_global(target)
    #fullname = globalprotocoldecl.get_full_name(gpd)

    rd_list = globalprotocoldecl_get_roledecllist_child(gpd)
    ri_list = get_roleinstantiationlist_child(node_)
    roleparam = get_target_parameter(rd_list, ri_list, rolearg)

    if roleparam is None:
        return None
    else:
        #{
        roles = []
        rd_iter = roledecllist_get_roledecl_children(rd_list).__iter__()
        for ri in roleinstantiationlist_get_roleinstantiation_children(
                ri_list):
            rd = rd_iter.next()
            #roles.append(roleinstantiation_pretty_print(ri))  # FIXME: string hack (localdo)
            #tmp = projector.rolemap[roleinstantiation_get_arg(ri)]
            tmp = roleinstantiation_get_arg(ri)
            roles.append((tmp, roleinstantiation_get_parameter(ri)))

        args = []
        arglist = get_argumentlist_child(node_)
        for arg in argumentlist_get_argument_children(arglist):
            args.append(argument_pretty_print(arg))
        """members = context_.get_members()

        for arg in globaldo.getglobaldoArgsChildren(globel):
            if util.get_node_type(arg) == constants.MESSAGE_SIGNATURE_NODE_TYPE:
                for payload in payloadList.getpayloadChildren(messagesignature.getpayloadListChild(arg)):
                    alias = payload.getpayloadType(payload)
                    payloads[len(payloads)-1][alias] = context_.getpayloadTypes()[alias]

        if not((fqmn, param) in visited.keys()) or not(globalprotocoldecl.get_name(gpd) in visited[(fqmn, param)]):
            target = project(context_.get_source(fqmn), context_, fqmn, gpd, param)  # FIXME: only need to do for target parameter
        imports[len(imports)-1].add(fqmn + '_' + param)"""

        if target in context_.get_members():
            # Full member name of target was specified
            #module_ = util.get_full_module_name_from_full_member_name(target)
            #proto = util.get_simple_member_name_from_full_member_name(target)
            projectionname = get_projected_member_name(target, roleparam)
            # FIXME: factor out local projection name generation with import
            # decl projection
            #projector.add_subprotocol_reference(target, roleparam)
        else:
            # TODO: several cases, could be via simple name of co-module_
            # protocol, or full name via member alias or module_ alias, etc.
            #
            # One option is to project all references to be fully qualified
            # (dropping aliases even?)
            raise RuntimeError("[Projector] globaldo TODO: " + target)

        return projector.nf.localdo(  #projector.rolemap[projector.role],
            projector.role, scope, projectionname, args, roles)
コード例 #2
0
def check_wellformedness(context_, target, node_):
    ris = get_roleinstantiation_children(node_)

    tree = context_.get_visible_global(target)
    rparamlist = roledecllist_get_roledecl_children(
                     globalprotocoldecl_get_roledecllist_child(tree))

    # Section 4.6.3 -- lengts of role-instantiation-list and target
    # role-decl-list are the same
    if len(ris) != len(rparamlist):
        util.report_error("Bad number of role arguments, expected: " + \
                          str(len(rparamlist)))

    croles = context_.get_roles()
    rparams = rparamlist.__iter__()
    rolemap = {}  # params -> args (as strings --
                  # maybe should do ROLE node_, as for argmap)
    for ri in ris:
        ours = roleinstantiation_get_arg(ri)
        next = rparams.next()
        theirs = roledecl_get_role_name(next)
        # Section 4.6.3 -- every role argument is bound and distinct
        if (ours not in croles) or ours in rolemap.values():
            util.report_error("Bad role argument: " + ours)
        if roleinstantiation_has_parameter_child(ri):
            tmp = roleinstantiation_get_parameter(ri)
            if theirs != tmp: 
                # Section 4.6.3 -- every instantiation parameter corresponds to
                # the declared parameter in the protocol declaration
                util.report_error("Bad role parameter: " + theirs + ", " +tmp)
        rolemap[roledecl_get_declaration_name(next)] = ours

    return rolemap
コード例 #3
0
def check_wellformedness(context_, target, node_):
    ris = get_roleinstantiation_children(node_)

    tree = context_.get_visible_global(target)
    rparamlist = roledecllist_get_roledecl_children(
                     globalprotocoldecl_get_roledecllist_child(tree))

    # Section 4.6.3 -- lengts of role-instantiation-list and target
    # role-decl-list are the same
    if len(ris) != len(rparamlist):
        util.report_error("Bad number of role arguments, expected: " + \
                          str(len(rparamlist)))

    croles = context_.get_roles()
    rparams = rparamlist.__iter__()
    rolemap = {}  # params -> args (as strings --
                  # maybe should do ROLE node_, as for argmap)
    for ri in ris:
        ours = roleinstantiation_get_arg(ri)
        next = rparams.next()
        theirs = roledecl_get_role_name(next)
        # Section 4.6.3 -- every role argument is bound and distinct
        if (ours not in croles) or ours in rolemap.values():
            util.report_error("Bad role argument: " + ours)
        if roleinstantiation_has_parameter_child(ri):
            tmp = roleinstantiation_get_parameter(ri)
            if theirs != tmp: 
                # Section 4.6.3 -- every instantiation parameter corresponds to
                # the declared parameter in the protocol declaration
                util.report_error("Bad role parameter: " + theirs + ", " +tmp)
        rolemap[roledecl_get_declaration_name(next)] = ours

    return rolemap
コード例 #4
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_
コード例 #5
0
def get_role_map(context_, target, node_):
    rolemap = {}  # params -> args (string -> string)
    tree = context_.get_visible_global(target)
    rparamlist = roledecllist_get_roledecl_children(
        globalprotocoldecl_get_roledecllist_child(tree))
    rparams = rparamlist.__iter__()
    ris = get_roleinstantiation_children(node_)
    for ri in ris:
        ours = roleinstantiation_get_arg(ri)  # returns string
        next = rparams.next()
        rolemap[roledecl_get_declaration_name(next)] = ours
    return rolemap
コード例 #6
0
def get_role_map(context_, target, node_):
    rolemap = {}  # params -> args (string -> string)
    tree = context_.get_visible_global(target)
    rparamlist = roledecllist_get_roledecl_children(
                     globalprotocoldecl_get_roledecllist_child(tree))
    rparams = rparamlist.__iter__()
    ris = get_roleinstantiation_children(node_)
    for ri in ris:
        ours = roleinstantiation_get_arg(ri)  # returns string
        next = rparams.next()
        rolemap[roledecl_get_declaration_name(next)] = ours
    return rolemap
コード例 #7
0
def get_target_parameter(rd_list, ri_list, rolearg):
    roleparam = None
    rd_iter = roledecllist_get_roledecl_children(rd_list).__iter__()
    for ri in roleinstantiationlist_get_roleinstantiation_children(ri_list):
        rd = rd_iter.next()
        if roleinstantiation_get_arg(ri) == rolearg:
            if roleinstantiation_get_parameter_child(ri):
                roleparam = roleinstantiation_get_parameter(ri)
            else:
                roleparam = roledecl_get_role_name(rd)
                # actually, this else case subsumes the first case
            break
    return roleparam
コード例 #8
0
ファイル: globaldo.py プロジェクト: rhu1/scribble-python
def get_target_parameter(rd_list, ri_list, rolearg):
    roleparam = None
    rd_iter = roledecllist_get_roledecl_children(rd_list).__iter__()
    for ri in roleinstantiationlist_get_children(ri_list):
        rd = rd_iter.next()
        if roleinstantiation_get_arg(ri) == rolearg:
            if roleinstantiation_get_parameter_child(ri):
                roleparam = roleinstantiation_get_parameter(ri)
            else:
                roleparam = roledecl_get_role_name(rd)
                # actually, this else case subsumes the first case
            break
    return roleparam
コード例 #9
0
ファイル: localdo.py プロジェクト: cogumbreiro/scribble-demo
 def get_target_parameter(self, context_):
     gpd = context_.get_visible_global(self.get_target())
     ri_list = self.get_roleinstantiations()
     rolearg = self.local_role
     rd_list = globalprotocoldecl_get_roledecllist_child(gpd)
     roleparam = None
     rd_iter = roledecllist_get_roledecl_children(rd_list).__iter__()
     for (a, p) in ri_list:
         rd = rd_iter.next()
         if a == rolearg:
             if p:
                 roleparam = p
             else:
                 roleparam = roledecl_get_role_name(rd)
                 # actually, this else case subsumes the first case
             break
     return roleparam
コード例 #10
0
 def get_target_parameter(self, context_):
     gpd = context_.get_visible_global(self.get_target())
     ri_list = self.get_roleinstantiations()
     rolearg = self.local_role
     rd_list = globalprotocoldecl_get_roledecllist_child(gpd)
     roleparam = None
     rd_iter = roledecllist_get_roledecl_children(rd_list).__iter__()
     for (a, p) in ri_list:
         rd = rd_iter.next()
         if a == rolearg:
             if p:
                 roleparam = p
             else:
                 roleparam = roledecl_get_role_name(rd)
                 # actually, this else case subsumes the first case
             break
     return roleparam
コード例 #11
0
ファイル: globaldo.py プロジェクト: rhu1/scribble-python
def project(projector, node_):
    context_ = projector.context
    rolearg = projector.role
    scope = get_scope(node_)
    target = get_target_full_name(context_, node_)
    gpd = context_.get_visible_global(target)
    #fullname = globalprotocoldecl.get_full_name(gpd)

    rd_list = globalprotocoldecl_get_roledecllist_child(gpd)
    ri_list = get_roleinstantiationlist_child(node_)
    roleparam = get_target_parameter(rd_list, ri_list, rolearg)

    if roleparam is None:
        return None
    else:
    #{
        roles = []
        rd_iter = roledecllist_get_roledecl_children(rd_list).__iter__()
        for ri in roleinstantiationlist_get_children(ri_list):
            rd = rd_iter.next()
            #roles.append(roleinstantiation_pretty_print(ri))  # FIXME: string hack (localdo)
            #tmp = projector.rolemap[roleinstantiation_get_arg(ri)]
            tmp = roleinstantiation_get_arg(ri)
            roles.append((tmp, roleinstantiation_get_parameter(ri)))

        args = []
        #pd_list = globalprotocoldecl_get_parameterdecllist_child(gpd)
        arglist = get_argumentlist_child(node_)
        ##for arg in argumentlist_get_argument_children(arglist):
        ##    args.append(argument_pretty_print(arg))
        #pd_iter = parameterdecllist_get_paramdecl_children(pd_list).__iter__()
        for arg in argumentlist_get_children(arglist):
            #pd = rd_iter.next()
            tmp = argument_get_arg(arg)
            args.append((tmp, argument_get_parameter(arg)))

        """members = context_.get_members()

        for arg in globaldo.getglobaldoArgsChildren(globel):
            if util.get_node_type(arg) == constants.MESSAGE_SIGNATURE_NODE_TYPE:
                for payload in payloadList.getpayloadChildren(messagesignature.getpayloadListChild(arg)):
                    alias = payload.getpayloadType(payload)
                    payloads[len(payloads)-1][alias] = context_.getpayloadTypes()[alias]

        if not((fqmn, param) in visited.keys()) or not(globalprotocoldecl.get_name(gpd) in visited[(fqmn, param)]):
            target = project(context_.get_source(fqmn), context_, fqmn, gpd, param)  # FIXME: only need to do for target parameter
        imports[len(imports)-1].add(fqmn + '_' + param)"""

        if target in context_.get_members():
            # Full member name of target was specified
            #module_ = util.get_full_module_name_from_full_member_name(target)
            #proto = util.get_simple_member_name_from_full_member_name(target)
            projectionname = get_projected_member_name(target, roleparam)
                # FIXME: factor out local projection name generation with import
                # decl projection
            #projector.add_subprotocol_reference(target, roleparam)
        else:
            # TODO: several cases, could be via simple name of co-module_
            # protocol, or full name via member alias or module_ alias, etc.
            #
            # One option is to project all references to be fully qualified
            # (dropping aliases even?)
            raise RuntimeError("[Projector] globaldo TODO: " + target)

        return projector.nf.localdo(#projector.rolemap[projector.role],
                                    projector.role,
                                    scope,
                                    projectionname,
                                    args,
                                    roles)