Ejemplo n.º 1
0
def get_full_name_from_visible_name(context_, globalproto):
    gpd = context_.get_visible_global(globalproto)
    if gpd is None:  # Should never happen?
        util.report_error("Bad protocol reference: " + target)
    module_ = gpd.getParent()
    modulefullname = moduledecl_get_full_name(
        module_get_moduledecl_child(module_))
    protofullname = modulefullname + '.' + globalprotocoldecl_get_name(gpd)
    return protofullname
Ejemplo n.º 2
0
def get_full_name_from_visible_name(context_, globalproto):
    gpd = context_.get_visible_global(globalproto)
    if gpd is None:  # Should never happen?
        util.report_error("Bad protocol reference: " + target)
    module_ = gpd.getParent()
    modulefullname = moduledecl_get_full_name(
                         module_get_moduledecl_child(module_))
    protofullname = modulefullname + '.' + globalprotocoldecl_get_name(gpd)
    return protofullname
Ejemplo n.º 3
0
def _get_self_visibility(context, module_):
    for ptd in module_get_payloadtypedecl_children(module_):
        n = payloadtypedecl_get_declaration_name(ptd)
        context = context.add_visible_payload(n, ptd)
    for gpd in module_get_globalprotocoldecl_children(module_):
        n = globalprotocoldecl_get_name(gpd)
        context = context.add_visible_global(n, gpd)
    for lpd in module_get_localprotocoldecl_children(module_):
        n = localprotocoldecl_get_name(lpd)
        context = context.add_visible_local(n, lpd)
    importmembers = module_get_importmember_children(module_)
    for im in importmembers:
        util.report_error("TODO: member import: " + im)
        # FIXME: members
    return context
Ejemplo n.º 4
0
def _get_self_visibility(context, module_):
    for ptd in module_get_payloadtypedecl_children(module_):
        n = payloadtypedecl_get_declaration_name(ptd)
        context = context.add_visible_payload(n, ptd)
    for gpd in module_get_globalprotocoldecl_children(module_):
        n = globalprotocoldecl_get_name(gpd)
        context = context.add_visible_global(n, gpd)
    for lpd in module_get_localprotocoldecl_children(module_):
        n = localprotocoldecl_get_name(lpd)
        context = context.add_visible_local(n, lpd)
    importmembers = module_get_importmember_children(module_)
    for im in importmembers:
        util.report_error("TODO: member import: " + im)
        # FIXME: members
    return context
Ejemplo n.º 5
0
def _add_all_members(context_, fmn, module_):
    for ptd in module_get_payloadtypedecl_children(module_):
        n = payloadtypedecl_get_declaration_name(ptd)
        f = fmn + '.' + n
        context_ = context_.add_member(f, ptd)
    for gpd in module_get_globalprotocoldecl_children(module_):
        n = globalprotocoldecl_get_name(gpd)
        f = fmn + '.' + n
        context_ = context_.add_member(f, gpd)
    for lpd in module_get_localprotocoldecl_children(module_):
        n = localprotocoldecl_get_name(lpd)
        f = fmn + '.' + n
        context_ = context_.add_member(f, lpd)
    importmembers = module_get_importmember_children(module_)
    for im in importmembers:
        # TODO: members
        util.report_error("TODO member import: " + im)
    return context_
Ejemplo n.º 6
0
def _add_all_members(context_, fmn, module_):
    for ptd in module_get_payloadtypedecl_children(module_):
        n = payloadtypedecl_get_declaration_name(ptd)
        f = fmn + "." + n
        context_ = context_.add_member(f, ptd)
    for gpd in module_get_globalprotocoldecl_children(module_):
        n = globalprotocoldecl_get_name(gpd)
        f = fmn + "." + n
        context_ = context_.add_member(f, gpd)
    for lpd in module_get_localprotocoldecl_children(module_):
        n = localprotocoldecl_get_name(lpd)
        f = fmn + "." + n
        context_ = context_.add_member(f, lpd)
    importmembers = module_get_importmember_children(module_)
    for im in importmembers:
        # TODO: members
        util.report_error("TODO member import: " + im)
    return context_
Ejemplo n.º 7
0
def _get_module_members(context, dn, module_):
    for ptd in module_get_payloadtypedecl_children(module_):
        n = payloadtypedecl_get_declaration_name(ptd)
        f = dn + '.' + n
        context = context.add_visible_payload(f, ptd)
        #context = context.add_visible_payload(n, ptd)
    for gpd in module_get_globalprotocoldecl_children(module_):
        n = globalprotocoldecl_get_name(gpd)
        f = dn + '.' + n
        context = context.add_visible_global(f, gpd)
        #context = context.add_visible_global(n, gpd)
    for lpd in module_get_localprotocoldecl_children(module_):
        n = localprotocoldecl_get_name(lpd)
        f = dn + '.' + n
        context = context.add_visible_local(f, lpd)
        #context = context.add_visible_local(n, gpd)
    importmembers = module_get_importmember_children(module_)
    for im in importmembers:
        util.report_error("TODO member import: " + im)
        # TODO: members
    return context
Ejemplo n.º 8
0
def _get_module_members(context, dn, module_):
    for ptd in module_get_payloadtypedecl_children(module_):
        n = payloadtypedecl_get_declaration_name(ptd)
        f = dn + '.' + n
        context = context.add_visible_payload(f, ptd)
        #context = context.add_visible_payload(n, ptd)
    for gpd in module_get_globalprotocoldecl_children(module_):
        n = globalprotocoldecl_get_name(gpd)
        f = dn + '.' + n
        context = context.add_visible_global(f, gpd)
        #context = context.add_visible_global(n, gpd)
    for lpd in module_get_localprotocoldecl_children(module_):
        n = localprotocoldecl_get_name(lpd)
        f = dn + '.' + n
        context = context.add_visible_local(f, lpd)
        #context = context.add_visible_local(n, gpd)
    importmembers = module_get_importmember_children(module_)
    for im in importmembers:
        util.report_error("TODO member import: " + im)
        # TODO: members
    return context
Ejemplo n.º 9
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.º 10
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
Ejemplo n.º 11
0
def check_wellformedness_visit(checker, node_):
    ##
    # Section 4.2 -- Simple name and filename of module condition checked in moduledecl_ (also currently checked earlier by moduleLoader)

    ##
    # Section 4.2 -- Distinct module names condition
    fmn = moduledecl_get_full_name(get_moduledecl_child(node_))
    smn_from_fmn = util.get_simple_module_name_from_full_module_name(fmn)
    names = [smn_from_fmn]
    for im in get_importmodule_children(node_):
        name = importmodule_get_declaration_name(im)
        if name in names:
            util.report_error("Bad module import declaration name: " + name)
        names.append(name)

    ##
    # Section 4.2 -- Distinct member names condition
    names = []
    for ptd in get_payloadtypedecl_children(node_):
        name = payloadtypedecl_get_declaration_name(ptd)
        if name in names:
            util.report_error("Bad payload type declaration name: " + name)
        names.append(name)
    for gpd in get_globalprotocoldecl_children(node_):
        name = globalprotocoldecl_get_name(gpd)
        if name in names:
            util.report_error("Bad global protocol declaration name: " + name)
        names.append(name)
    for lpd in get_localprotocoldecl_children(node_):
        name = localprotocoldecl_get_name(lpd)
        if name in names:
            util.report_error("Bad local protocol declaration name: " + name)
        names.append(name)
    for im in get_importmember_children(node_):
        # TODO: import member declaration names
        util.report_error("TODO member import: " + im)

    ##
    # Section 4.2 -- Well-formed import declarations and members
    #
    # Same visiting structure as traverse; in the general case, however,
    # well-formedness visiting needs to visit each child with a separate
    # context, so cannot directly reuse the traverse routine here
    visited = []
    moduledecl_ = get_moduledecl_child(node_)
    visited.append(checker.visit(moduledecl_))
    for im in get_importmodule_children(node_):
        visited.append(checker.visit(im))
    for im in get_importmember_children(node_):
        util.report_error("Member Import not supported yet.")
    # FIXME: also members
    for ptd in get_payloadtypedecl_children(node_):
        visited.append(checker.visit(ptd))
    for gpd in get_globalprotocoldecl_children(node_):
        visited.append(checker.visit(gpd))
    for lpd in get_localprotocoldecl_children(node_):
        # visited.append(checker.visit(lpd))
        # TODO
        util.report_warning("[WellformednessChecker] Skipping localprotocoldecl: " + localprotocoldecl_get_name(lpd))
        # print "Skipped:\n", localprotocoldecl_pretty_print(lpd)
    # rebuild using new children
    return util.antlr_dupnode_and_replace_children(node_, visited)
Ejemplo n.º 12
0
def check_wellformedness_visit(checker, node_):
    ##
    # Section 4.2 -- Simple name and filename of module condition checked in moduledecl_ (also currently checked earlier by moduleLoader)

    ##
    # Section 4.2 -- Distinct module names condition
    fmn = moduledecl_get_full_name(get_moduledecl_child(node_))
    smn_from_fmn = util.get_simple_module_name_from_full_module_name(fmn)
    names = [smn_from_fmn]
    for im in get_importmodule_children(node_):
        name = importmodule_get_declaration_name(im)
        if name in names:
            util.report_error("Bad module import declaration name: " + name)
        names.append(name)

    ##
    # Section 4.2 -- Distinct member names condition
    names = []
    for ptd in get_payloadtypedecl_children(node_):
        name = payloadtypedecl_get_declaration_name(ptd)
        if name in names:
            util.report_error("Bad payload type declaration name: " + name)
        names.append(name)
    for gpd in get_globalprotocoldecl_children(node_):
        name = globalprotocoldecl_get_name(gpd)
        if name in names:
            util.report_error("Bad global protocol declaration name: " + name)
        names.append(name)
    for lpd in get_localprotocoldecl_children(node_):
        name = localprotocoldecl_get_name(lpd)
        if name in names:
            util.report_error("Bad local protocol declaration name: " + name)
        names.append(name)
    for im in get_importmember_children(node_):
        # TODO: import member declaration names
        util.report_error("TODO member import: " + im)

    ##
    # Section 4.2 -- Well-formed import declarations and members
    #
    # Same visiting structure as traverse; in the general case, however,
    # well-formedness visiting needs to visit each child with a separate
    # context, so cannot directly reuse the traverse routine here
    visited = []
    moduledecl_ = get_moduledecl_child(node_)
    visited.append(checker.visit(moduledecl_))
    for im in get_importmodule_children(node_):
        visited.append(checker.visit(im))
    for im in get_importmember_children(node_):
        util.report_error("Member Import not supported yet.")
    # FIXME: also members
    for ptd in get_payloadtypedecl_children(node_):
        visited.append(checker.visit(ptd))
    for gpd in get_globalprotocoldecl_children(node_):
        visited.append(checker.visit(gpd))
    for lpd in get_localprotocoldecl_children(node_):
        #visited.append(checker.visit(lpd))
        # TODO
        util.report_warning("[WellformednessChecker] Skipping localprotocoldecl: " \
                            + localprotocoldecl_get_name(lpd))
        #print "Skipped:\n", localprotocoldecl_pretty_print(lpd)
    # rebuild using new children
    return util.antlr_dupnode_and_replace_children(node_, visited)
Ejemplo n.º 13
0
 def project_globalprotocoldecl(self, context_, gpd, role_):#, rolemap):
     self._protocol = globalprotocoldecl_get_name(gpd)
         # simple (declaration) name
     return self.project(context_, gpd, role_)#, rolemap)
Ejemplo n.º 14
0
 def project_globalprotocoldecl(self, context_, gpd, role_):  #, rolemap):
     self._protocol = globalprotocoldecl_get_name(gpd)
     # simple (declaration) name
     return self.project(context_, gpd, role_)  #, rolemap)