def check_wellformedness(checker, target, node_):
    context_ = checker.get_context()

    tree = context_.get_visible_global(target)
    pdl = globalprotocoldecl_get_parameterdecllist_child(tree)
    paramlist = parameterdecllist_get_parameterdecl_children(pdl)

    # Section 4.6.3 -- lengths of argument list and parameter decl list are the
    # same
    args = get_argument_children(node_)
    if len(args) != len(paramlist):  # This check includes empty lists
        util.report_error("Bad number of arguments, expected: " + \
                          str(len(paramlist)))

    argmap = {}  # params -> args (args are the MESSAGESIGNATURE nodes)
    params = paramlist.__iter__()
    for argpair in args:
        #{
        # FIXME: tidy up usage of argpair and arg
        #arg = argument.get_arg(argpair)
        arg = argument_get_arg_child(argpair)
        targ_pd = params.next()

        # Section 4.6.3 -- for each argument, one of the two cases must hold:
        kind = parameterdecl_get_kind(targ_pd)
        #if kind == constants.SIGKW:  # HACK: KW constant
        # Section 4.6.3 -- case (1): the target parameter is a sig parameter
        if kind == constants.KIND_MESSAGE_SIGNATURE:
            # Should annotations be allowed here?
            if util.get_node_type(
                    arg) == constants.MESSAGE_SIGNATURE_NODE_TYPE:
                # Section 4.6.3 -- the argument should be a well-formed
                # message-signature
                messagesignature_check_wellformedness(checker, arg)
                # Well-formed message-signature
            else:
                # Section 4.6.3 -- the argument should be a bound sig parameter
                #util.report_error('Expected sig argument: ' + arg)
                param = argument_get_arg(argpair)
                if param not in context_.get_parameters().keys():
                    # The argument isn't a valid parameter
                    util.report_error("Bad argument : " + param)
                #if context_.get_parameter(param) != constants.SIGKW:
                if context_.get_parameter(param) != \
                        constants.KIND_MESSAGE_SIGNATURE:
                    util.report_error("Expected sig parameter: " + param)
            ##argmap[parameter.get_parameter_name(params.next())] = arg
        #elif kind == constants.TYPEKW:
        # Section 4.6.3 -- case (2): the target parameter is a type parameter
        elif kind == constants.KIND_PAYLOAD_TYPE:
            # Section 4.6.3 -- the argument should be a visible payload or a
            # bound type parameter
            val = argument_get_arg(argpair)
            if val not in context_.get_visible_payloads():
                # FIXME: factor out with payload
                #if context_.get_current_module() + '.' + val in context_.get_visible_payloads():
                if val not in context_.get_parameters().keys():
                    util.report_error("Bad argument: " + val)
                ##if not(context_.get_parameter(val) == constants.TYPEKW):
                if context_.get_parameter(val) != constants.KIND_PAYLOAD_TYPE:
                    util.report_error("Expected type parameter: " + val)
        else:
            raise Exception("Shouldn't get in here: " + kind)

        # Section 4.6.3 -- argument parameter must match the declared parameter
        # in the target protocol declaration
        if argument_has_parameter_child(argpair):
            theirs = argument_get_parameter(argpair)
            if theirs != parameterdecl_get_name(targ_pd):
                util.report_error("Bad role parameter: " + theirs)

        argmap[parameterdecl_get_declaration_name(targ_pd)] = arg
    #}
    return argmap
Esempio n. 2
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_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)
Esempio n. 3
0
def check_wellformedness(checker, target, node_):
    context_ = checker.get_context()

    tree = context_.get_visible_global(target)
    pdl = globalprotocoldecl_get_parameterdecllist_child(tree)
    paramlist = parameterdecllist_get_parameterdecl_children(pdl)

    # Section 4.6.3 -- lengths of argument list and parameter decl list are the
    # same
    args = get_argument_children(node_)
    if len(args) != len(paramlist):  # This check includes empty lists
        util.report_error("Bad number of arguments, expected: " + \
                          str(len(paramlist)))

    argmap = {}  # params -> args (args are the MESSAGESIGNATURE nodes)
    params = paramlist.__iter__()
    for argpair in args:
    #{
        # FIXME: tidy up usage of argpair and arg
        #arg = argument.get_arg(argpair)
        arg = argument_get_arg_child(argpair)
        targ_pd = params.next()

        # Section 4.6.3 -- for each argument, one of the two cases must hold:
        kind = parameterdecl_get_kind(targ_pd)
        #if kind == constants.SIGKW:  # HACK: KW constant
        # Section 4.6.3 -- case (1): the target parameter is a sig parameter
        if kind == constants.KIND_MESSAGE_SIGNATURE:
            # Should annotations be allowed here?
            if util.get_node_type(arg) == constants.MESSAGE_SIGNATURE_NODE_TYPE:
                # Section 4.6.3 -- the argument should be a well-formed
                # message-signature
                messagesignature_check_wellformedness(checker, arg)
                    # Well-formed message-signature
            else:
              # Section 4.6.3 -- the argument should be a bound sig parameter
                #util.report_error('Expected sig argument: ' + arg)
                param = argument_get_arg(argpair)
                if param not in context_.get_parameters().keys():
                    # The argument isn't a valid parameter
                    util.report_error("Bad argument : " + param)
                #if context_.get_parameter(param) != constants.SIGKW:
                if context_.get_parameter(param) != \
                        constants.KIND_MESSAGE_SIGNATURE:
                    util.report_error("Expected sig parameter: " + param)
            ##argmap[parameter.get_parameter_name(params.next())] = arg
        #elif kind == constants.TYPEKW:
        # Section 4.6.3 -- case (2): the target parameter is a type parameter
        elif kind == constants.KIND_PAYLOAD_TYPE:
            # Section 4.6.3 -- the argument should be a visible payload or a
            # bound type parameter
            val = argument_get_arg(argpair)
            if val not in context_.get_visible_payloads():
                # FIXME: factor out with payload
                #if context_.get_current_module() + '.' + val in context_.get_visible_payloads():
                if val not in context_.get_parameters().keys():
                    util.report_error("Bad argument: " + val)
                ##if not(context_.get_parameter(val) == constants.TYPEKW):
                if context_.get_parameter(val) != constants.KIND_PAYLOAD_TYPE:
                    util.report_error("Expected type parameter: " + val)
        else:
            raise Exception("Shouldn't get in here: " + kind)

        # Section 4.6.3 -- argument parameter must match the declared parameter
        # in the target protocol declaration
        if argument_has_parameter_child(argpair):
            theirs = argument_get_parameter(argpair)
            if theirs != parameterdecl_get_name(targ_pd):
                util.report_error("Bad role parameter: " + theirs)

        argmap[parameterdecl_get_declaration_name(targ_pd)] = arg
    #}
    return argmap