Ejemplo n.º 1
0
def check_wellformedness(checker, node_):
    context_ = checker.get_context()

    sigs = get_message_children(node_)
    subj = get_role(node_)

    # Section 4.6.9 -- bound interrupt role
    if not context_.is_role_declared(subj):
        util.report_error("Bad interrupt role: " + subj)

    tmp = context_.get_operators().items()
    for sig in sigs:
        if util.get_node_type(sig) == constants.MESSAGE_SIGNATURE_NODE_TYPE:
            #tmp = context_.get_operators().items()
            # Section 4.6.9 -- well-formed message signature
            messagesignature_check_wellformedness(checker, sig)
            op = context_.get_current_scope() + '.' \
                 + messagesignature_get_operator(sig) 
                    # interrupt sig belongs to the scope of the interruptible
            for (src, _), ops in tmp:
                if op in ops:
                    # Section 4.6.9 -- op is not in any potential ops set of
                    # block for subj
                    if subj == src:
                        util.report_error("Bad interrupt operator: " + op)
                    #context_ = context_.add_operator()
                        # FIXME: can't do currently: interrupt messages have no
                        # specific dest (need to look up all possible
                        # destinations, or could make a special broadcast value
                        # constant?) -- top-level interruptible inside a choice
                        # block can also be an enabling op
        else:
            raise RuntimeError("TODO: " + parameter_get_parameter_name(sig))
Ejemplo n.º 2
0
def check_wellformedness(checker, node_):
    context_ = checker.get_context()

    sigs = get_message_children(node_)
    subj = get_role(node_)

    # Section 4.6.9 -- bound interrupt role
    if not context_.is_role_declared(subj):
        util.report_error("Bad interrupt role: " + subj)

    tmp = context_.get_operators().items()
    for sig in sigs:
        if util.get_node_type(sig) == constants.MESSAGE_SIGNATURE_NODE_TYPE:
            #tmp = context_.get_operators().items()
            # Section 4.6.9 -- well-formed message signature
            messagesignature_check_wellformedness(checker, sig)
            op = context_.get_current_scope() + '.' \
                 + messagesignature_get_operator(sig)
            # interrupt sig belongs to the scope of the interruptible
            for (src, _), ops in tmp:
                if op in ops:
                    # Section 4.6.9 -- op is not in any potential ops set of
                    # block for subj
                    if subj == src:
                        util.report_error("Bad interrupt operator: " + op)
                    #context_ = context_.add_operator()
                    # FIXME: can't do currently: interrupt messages have no
                    # specific dest (need to look up all possible
                    # destinations, or could make a special broadcast value
                    # constant?) -- top-level interruptible inside a choice
                    # block can also be an enabling op
        else:
            raise RuntimeError("TODO: " + parameter_get_parameter_name(sig))
def check_wellformedness_enter(checker, node_):
    context = checker.get_context()
    msg = get_message_child(node_)  # node
    mtype = util.get_node_type(msg)
    src = get_source(node_)  # string
    dests = get_destinations(node_)  # string

    # Will be assigned depending on whether message is a concrete signature or a
    # parameter
    op = None  # string
    param = None  # string

    # Section 4.6.5 -- message is a well-formed message-signature or a bound sig
    # parameter
    if mtype == constants.MESSAGE_SIGNATURE_NODE_TYPE:
        # Section 4.6.5 -- Well-formed message-signature
        messagesignature_check_wellformedness(checker, msg)
        #op = messagesignature.get_operator(msg)
        op = context.get_current_scope() + '.' + messagesignature_get_operator(
            msg)
    else:
        # Not a message signature, should be a sig parameter
        param = parameter_get_name(msg)
        op = param
        params = context.get_parameters()
        if not param in params.keys():  # Bound parameter
            util.report_error("Bad parameter: " + param)
        if params[param] != constants.KIND_MESSAGE_SIGNATURE:
            # sig parameter  # HACK?: using the KW
            util.report_error("Bad type parameter: " + param)

    # Section 4.6.5 -- source role is bound
    if not context.is_role_declared(src):
        util.report_error("Bad source role: " + src)
    # Section 4.6.6 -- the non-at roles of a choice must occur in receiver position
    # (i.e. be "enabled" -- the at-role is enabled implicitly) before occuring in
    # any non- transfer-receiver position, such as a nested choice at-position
    # here)
    if not context.is_role_enabled(src):
        util.report_error("Role not enabled: " + src)

    # Destination roles
    tmp = []
    for dest in dests:
        # Section 4.6.5 -- bound destination roles
        if not context.is_role_declared(dest):
            util.report_error("Bad destination role: " + dest)
        if dest in tmp:  # Section 4.6.5 -- distinct destination roles
            util.report_error("Duplicate destination role: " + dest)
        tmp.append(dest)
def check_wellformedness_enter(checker, node_):
    context = checker.get_context()
    msg = get_message_child(node_)   # node
    mtype = util.get_node_type(msg)
    src = get_source(node_)         # string
    dests = get_destinations(node_) # string

    # Will be assigned depending on whether message is a concrete signature or a
    # parameter
    op = None     # string
    param = None  # string

    # Section 4.6.5 -- message is a well-formed message-signature or a bound sig
    # parameter
    if mtype == constants.MESSAGE_SIGNATURE_NODE_TYPE:
        # Section 4.6.5 -- Well-formed message-signature
        messagesignature_check_wellformedness(checker, msg)
        #op = messagesignature.get_operator(msg)
        op = context.get_current_scope() + '.' + messagesignature_get_operator(msg)
    else:
        # Not a message signature, should be a sig parameter
        param = parameter_get_name(msg)
        op = param
        params = context.get_parameters()
        if not param in params.keys():  # Bound parameter
            util.report_error("Bad parameter: " + param)
        if params[param] != constants.KIND_MESSAGE_SIGNATURE:
            # sig parameter  # HACK?: using the KW
            util.report_error("Bad type parameter: " + param)

    # Section 4.6.5 -- source role is bound
    if not context.is_role_declared(src):
        util.report_error("Bad source role: " + src)
    # Section 4.6.6 -- the non-at roles of a choice must occur in receiver position
    # (i.e. be "enabled" -- the at-role is enabled implicitly) before occuring in
    # any non- transfer-receiver position, such as a nested choice at-position
    # here)
    if not context.is_role_enabled(src):
        util.report_error("Role not enabled: " + src)

    # Destination roles
    tmp = []
    for dest in dests:
        # Section 4.6.5 -- bound destination roles
        if not context.is_role_declared(dest):
            util.report_error("Bad destination role: " + dest)
        if dest in tmp:  # Section 4.6.5 -- distinct destination roles
            util.report_error("Duplicate destination role: " + dest)
        tmp.append(dest)
Ejemplo n.º 5
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
Ejemplo n.º 6
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