def pretty_print(node_): text = constants.GLOBAL_KW + ' ' + constants.PROTOCOL_KW + ' ' text = text + get_name(node_) pds = get_parameterdecllist_child(node_) if util.get_node_type(pds) != parameterdecllist_EMPTY_PARAMETER_DECL_LIST: text = text + parameterdecllist_pretty_print(pds) text = text + roledecllist_pretty_print(get_roledecllist_child(node_)) body = get_child(node_) if util.get_node_type(body) == constants.GLOBAL_PROTOCOL_DEF_NODE_TYPE: text = text + '\n' + util.pretty_print(body) else: raise RuntimeError("TODO: ") return text
def _pretty_print_aux(p, r, paramdecllist_, roledecllist_, body): text = "" text = text + constants.LOCAL_KW + ' ' + constants.PROTOCOL_KW + ' ' text = text + p + ' ' text = text + constants.AT_KW + ' ' + role_get_role_name(r) if util.get_node_type(paramdecllist_) != \ parameterdecllist_EMPTY_PARAMETER_DECL_LIST: text = text + parameterdecllist_pretty_print(paramdecllist_) text = text + roledecllist_pretty_print(roledecllist_) child = body if util.get_node_type(child) == constants.LOCAL_PROTOCOL_DEF_NODE_TYPE: text = text + localprotocoldef_pretty_print(child) else: raise RuntimeError("TODO:", util.get_node_type(child)) return text
def project(projector, node_): src = get_source(node_) dests = get_destinations(node_) if src == projector.role or projector.role in dests: child = get_message_child(node_) message = None if util.get_node_type(child) == constants.MESSAGE_SIGNATURE_NODE_TYPE: message = messagesignature_pretty_print( child) # FIXME: string hack else: message = parameter_get_name(child) # FIXME: string hack if src == projector.role: if projector.role in dests: util.report_error("Self communication not supported.") #new_dests = util.replace_in_list(dests, projector.rolemap) new_dests = dests return projector.nf.localsend(projector.role, new_dests, message) if projector.role in dests: if src == projector.role: util.report_error("Self communication not supported.") #new_src = util.replace_in_list([src], projector.rolemap)[0] new_src = src return projector.nf.localreceive(projector.role, new_src, message) else: return None # OK to use None as "empty projection"?
def project(projector, node_): src = get_source(node_) dests = get_destinations(node_) if src == projector.role or projector.role in dests: child = get_message_child(node_) message = None if util.get_node_type(child) == constants.MESSAGE_SIGNATURE_NODE_TYPE: message = messagesignature_pretty_print(child) # FIXME: string hack else: message = parameter_get_name(child) # FIXME: string hack if src == projector.role: if projector.role in dests: util.report_error("Self communication not supported.") #new_dests = util.replace_in_list(dests, projector.rolemap) new_dests = dests return projector.nf.localsend(projector.role, new_dests, message) if projector.role in dests: if src == projector.role: util.report_error("Self communication not supported.") #new_src = util.replace_in_list([src], projector.rolemap)[0] new_src = src return projector.nf.localreceive(projector.role, new_src, message) else: return None # OK to use None as "empty projection"?
def _pretty_print_aux(sig): if util.get_node_type(sig) == constants.MESSAGE_SIGNATURE_NODE_TYPE: return messagesignature_pretty_print(sig) #text = text + util.pretty_print(sig) else: # TODO: parameter raise RuntimeError("TODO: " + parameter_get_parameter_name(sig))
def get_arg(node_): arg = get_arg_child(node_) if util.get_node_type(arg) == constants.MESSAGE_SIGNATURE_NODE_TYPE: # FIXME: broken if type/parameter name happens to be 'MESSAGESIGNATURE' return messagesignature_pretty_print(arg) # Is this right? else: return arg.getText() # payload type or parameter name
def get_importdecl_children(node_): res = [] for node_ in node_.getChildren(): ntype = util.get_node_type(node_) if ntype == constants.IMPORT_MODULE_NODE_TYPE or ntype == constants.IMPORT_MEMBER_NODE_TYPE: res.append(node_) return res
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 get_importdecl_children(node_): res = [] for node_ in node_.getChildren(): ntype = util.get_node_type(node_) if ntype == constants.IMPORT_MODULE_NODE_TYPE or \ ntype == constants.IMPORT_MEMBER_NODE_TYPE: res.append(node_) return res
def project(projector, node_): scope = get_scope(node_) gblock = get_block_child(node_) block = projector.visit(gblock) throw = None # localthrow # FIXME: need destination roles catches = [] # [localcatch] #RoleCollector() # Couldn't import conveniently (cyclic) involved = projector.rc.collect_roles(gblock) for i in get_interrupt_children(node_): subj = globalinterrupt_get_role(i) # String involved.add(subj) throw_messages = [] for i in get_interrupt_children(node_): subj = globalinterrupt_get_role(i) # String roles = list(involved - set([subj])) messages = [] for sig in globalinterrupt_get_message_children(i): # Factor out with interrupt, message transfer, argument, etc. if util.get_node_type(sig) == \ constants.MESSAGE_SIGNATURE_NODE_TYPE: messages.append(messagesignature_pretty_print(sig)) else: messages.append(parameter_pretty_print(sig)) if projector.role == subj and len(roles) > 0: #throws.append(projector.nf.localthrow(dests, messages)) #new_roles = util.replace_in_list(roles, projector.rolemap) new_roles = roles """throw = projector.nf.localthrow(#projector.rolemap[projector.role], projector.role, new_roles, messages)""" throw_messages.extend(messages) else: catches.append( projector.nf.localcatch( #projector.rolemap[projector.role], projector.role, #projector.rolemap[subj], subj, messages)) if throw_messages: throw = projector.nf.localthrow(projector.role, new_roles, throw_messages) if (not block.is_empty()) or throw: # Section 5.3.5 -- if R is involved in the interruptible (if it is # involved in the block or is a thrower) return projector.nf.localinterruptible( #projector.rolemap[projector.role], scope, block, throw, catches) projector.role, scope, block, throw, catches) else: return None
def traverse(traverser, node_): traversed = [] msg = get_message_child(node_) if util.get_node_type(msg) == constants.MESSAGE_SIGNATURE_NODE_TYPE: traversed.append(traverser.traverse(msg)) else: traversed.append(traverser.traverse_untyped_leaf(msg)) traversed.append(traverser.traverse_untyped_leaf(get_source_child(node_))) return util.antlr_dupnode_and_replace_children(node_, traversed)
def _visit_globalinterrupt( self, node ): # FIXME: not actually permitted by the syntax yet, but for later rolemap = self.getroleMap() argmap = self.getArgMap() dup = node.dupNode() #util.report_error('[NameSubstitutor] TODO: ' + node) # FIXME rolenode = globalinterrupt.get_role_child(node) msgnodes = globalinterrupt.get_message_children(node) dest = role.get_role_name( rolenode) # FIXME: factor out with globalmessagetransfer tmp = rolenode.dupNode() if dest in rolemap.keys(): val = rolemap[dest] tmp.token = copy.deepcopy(rolenode.token) util.set_node_type(tmp, val) dup.addChild(tmp) for mn in msgnodes: tmp = mn.dupNode() # FIXME: factor out with globalmessagetransfer if util.get_node_type(mn) != constants.MESSAGE_SIGNATURE_NODE_TYPE: msg = parameter.get_parameter_name( mn) # parameter or message signature if msg in argmap.keys(): # a param to substitute val = argmap[ msg] # message signature or another parameter? tmp.token = copy.deepcopy( mn.token ) # HACK: does it conflict with any parser meta data? e.g. line number? #tmp.token.setText(_argmap[msg].getText()) util.set_node_type(tmp, util.get_node_type(val)) for mn in val.getChildren(): tmp.addChild(copy.deepcopy(mn)) else: for mn in mn.getChildren(): tmp.addChild(copy.deepcopy(mn)) #tmp.addChild(tmp) # If a parameter but not a substitution object, then the dupNode for tmp is enough dup.addChild(tmp) return dup
def pretty_print(node_): text = '' message = get_message_child(node_) if util.get_node_type(message) == constants.MESSAGE_SIGNATURE_NODE_TYPE: text = text + messagesignature_pretty_print(message) else: text = text + parameter_pretty_print(message) text = text + ' ' + constants.FROM_KW + ' ' text = text + get_source(node_) text = text + ';' return text
def traverse(traverser, node_): traversed = [] arg = get_arg_child(node_) if util.get_node_type(arg) == constants.MESSAGE_SIGNATURE_NODE_TYPE: traversed.append(traverser.traverse(arg)) else: traversed.append(traverser.traverse_untyped_leaf(arg)) if has_parameter_child(node_): param = get_parameter_child(node_) traversed.append(traverser.traverse_untyped_leaf(param)) new = util.antlr_dupnode_and_replace_children(node_, traversed) return new
def _traverse_globalinteractionsequence(self, node_): traversed = [] for child in globalinteractionsequence_get_children(node_): next = self.traverse(child) if util.get_node_type(next) == \ constants.GLOBAL_INTERACTION_SEQUENCE_NODE_TYPE: # No need to do recursively for c in globalinteractionsequence_get_children(next): traversed.append(c) else: traversed.append(next) return util.antlr_dupnode_and_replace_children(node_, traversed)
def project(projector, node_): scope = get_scope(node_) gblock = get_block_child(node_) block = projector.visit(gblock) throw = None # localthrow # FIXME: need destination roles catches = [] # [localcatch] #RoleCollector() # Couldn't import conveniently (cyclic) involved = projector.rc.collect_roles(gblock) for i in get_interrupt_children(node_): subj = globalinterrupt_get_role(i) # String involved.add(subj) throw_messages = [] for i in get_interrupt_children(node_): subj = globalinterrupt_get_role(i) # String roles = list(involved - set([subj])) messages = [] for sig in globalinterrupt_get_message_children(i): # Factor out with interrupt, message transfer, argument, etc. if util.get_node_type(sig) == \ constants.MESSAGE_SIGNATURE_NODE_TYPE: messages.append(messagesignature_pretty_print(sig)) else: messages.append(parameter_pretty_print(sig)) if projector.role == subj and len(roles) > 0: #throws.append(projector.nf.localthrow(dests, messages)) #new_roles = util.replace_in_list(roles, projector.rolemap) new_roles = roles """throw = projector.nf.localthrow(#projector.rolemap[projector.role], projector.role, new_roles, messages)""" throw_messages.extend(messages) else: catches.append(projector.nf.localcatch( #projector.rolemap[projector.role], projector.role, #projector.rolemap[subj], subj, messages)) if throw_messages: throw = projector.nf.localthrow(projector.role, new_roles, throw_messages) if (not block.is_empty()) or throw: # Section 5.3.5 -- if R is involved in the interruptible (if it is # involved in the block or is a thrower) return projector.nf.localinterruptible( #projector.rolemap[projector.role], scope, block, throw, catches) projector.role, scope, block, throw, catches) else: return None
def traverse(traverser, node): traversed = [] for dest in node.getChildren()[: _get_tokw_child_index(node) + 1]: # includes TO separator child traversed.append(traverser.traverse_untyped_leaf(dest)) for message in get_message_children(node): if util.get_node_type(message) == constants.MESSAGE_SIGNATURE_NODE_TYPE: traversed.append(traverser.traverse(message)) else: traversed.append(traverser.traverse_untyped_leaf(message)) new = util.antlr_dupnode_and_replace_children(node, traversed) return new
def traverse(traverser, node): traversed = [] for dest in node.getChildren()[:_get_tokw_child_index(node) + 1]: # includes TO separator child traversed.append(traverser.traverse_untyped_leaf(dest)) for message in get_message_children(node): if util.get_node_type( message) == constants.MESSAGE_SIGNATURE_NODE_TYPE: traversed.append(traverser.traverse(message)) else: traversed.append(traverser.traverse_untyped_leaf(message)) new = util.antlr_dupnode_and_replace_children(node, traversed) return new
def _visit_globalinterrupt(self, node): # FIXME: not actually permitted by the syntax yet, but for later rolemap = self.getroleMap() argmap = self.getArgMap() dup = node.dupNode() # util.report_error('[NameSubstitutor] TODO: ' + node) # FIXME rolenode = globalinterrupt.get_role_child(node) msgnodes = globalinterrupt.get_message_children(node) dest = role.get_role_name(rolenode) # FIXME: factor out with globalmessagetransfer tmp = rolenode.dupNode() if dest in rolemap.keys(): val = rolemap[dest] tmp.token = copy.deepcopy(rolenode.token) util.set_node_type(tmp, val) dup.addChild(tmp) for mn in msgnodes: tmp = mn.dupNode() # FIXME: factor out with globalmessagetransfer if util.get_node_type(mn) != constants.MESSAGE_SIGNATURE_NODE_TYPE: msg = parameter.get_parameter_name(mn) # parameter or message signature if msg in argmap.keys(): # a param to substitute val = argmap[msg] # message signature or another parameter? tmp.token = copy.deepcopy( mn.token ) # HACK: does it conflict with any parser meta data? e.g. line number? # tmp.token.setText(_argmap[msg].getText()) util.set_node_type(tmp, util.get_node_type(val)) for mn in val.getChildren(): tmp.addChild(copy.deepcopy(mn)) else: for mn in mn.getChildren(): tmp.addChild(copy.deepcopy(mn)) # tmp.addChild(tmp) # If a parameter but not a substitution object, then the dupNode for tmp is enough dup.addChild(tmp) return dup
def pretty_print(node_): text = "" message = get_message_child(node_) if util.get_node_type(message) == constants.MESSAGE_SIGNATURE_NODE_TYPE: text = text + messagesignature_pretty_print(message) else: text = text + parameter_pretty_print(message) text = text + ' ' + constants.TO_KW + ' ' dests = get_destinations(node_) text = text + dests[0] for dest in dests[1:]: text = text + ', ' + dest text = text + ';' return text
def _output_projections_to_modules(context_, target_globalname, localrole, dir): members = context_.get_members() if target_globalname not in members.keys(): util.report_error("[Projection] Unknown protocol: " + \ target_globalname) #+ ", " + str(members)) gpd = context_.get_member(target_globalname) if util.get_node_type(gpd) != constants.GLOBAL_PROTOCOL_DECL_NODE_TYPE: util.report_error("[Projection] Not a global protocol declaration: " + target_globalname) if localrole not in globalprotocoldecl_get_role_names(gpd): util.report_error("[Projection] Projection role not declared: " + localrole) target_localname = globaldo_get_projected_member_name(target_globalname, localrole) todo = [target_localname] lpd = context_.get_projection(target_localname) subprotos = SubprotocolCollector(context_).collect_subprotocols(lpd, True) todo.extend(subprotos) # Includes target_globalname (even if not used recursively) # Write each subprotocol to a separately projected module for subproto in todo: globalmodulename = \ util.get_global_module_name_from_projected_member_name(subproto) # FIXME: not working if member/role names contain underscores; but # good to run subprotocol collection on local protocol. best way may # be to record a mapping between projected names and the global/role # names they come from globalmodule = context_.get_module(globalmodulename) projector = Projector() lm = projector.project_module(context_, globalmodule, subproto, todo) # subproto is the full local name lm = lm.addlocalprotocoldecl(context_.get_projection(subproto)) fmn = lm.get_full_name() filepath = None if dir is None: # FIXME: factor out with e.g. globaldo and importmodule projection filename = util.get_simple_module_name_from_full_module_name(fmn) \ + '.' + constants.SCRIBBLE_FILE_EXTENSION sp = context_.get_source(globalmodulename) filepath = util.parse_directory_from_filepath(sp) + '/' + filename # FIXME: double slashes being introduced somewhere else: filepath = dir + '/' + \ util.convert_full_module_name_to_filepath(fmn) _write_module(lm, filepath) """print '[DEBUG] Projection of ' + target_globalname + ' for ' + \
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)
def traverse(traverser, node_): name = get_name_child(node_) roledecllist_ = get_roledecllist_child(node_) pds = get_parameterdecllist_child(node_) body = get_child(node_) traversed = [] traversed.append(name) # No need to traverse if util.get_node_type(pds) == parameterdecllist_EMPTY_PARAMETER_DECL_LIST: traversed.append(pds) else: traversed.append(traverser.traverse(pds)) traversed.append(traverser.traverse(roledecllist_)) traversed.append(traverser.traverse(body)) # rebuild using new children return util.antlr_dupnode_and_replace_children(node_, traversed)
def pretty_print(node_): text = "" message = get_message_child(node_) if util.get_node_type(message) == constants.MESSAGE_SIGNATURE_NODE_TYPE: text = text + messagesignature_pretty_print(message) else: text = text + parameter_pretty_print(message) text = text + ' ' + constants.FROM_KW + ' ' text = text + get_source(node_) text = text + ' ' + constants.TO_KW + ' ' dests = get_destinations(node_) text = text + dests[0] for dest in dests[1:]: text = text + ', ' + dest text = text + ';' return text
def context_visitor_visit(cv, node_): name = get_name_child(node_) pds = get_parameterdecllist_child(node_) roledecllist_ = get_roledecllist_child(node_) body = get_child(node_) # globalprotocoldef or GlobalProtocolInstance visited = [] visited.append(name) # No need to visit if util.get_node_type(pds) == parameterdecllist_EMPTY_PARAMETER_DECL_LIST: visited.append(pds) else: visited.append(cv.visit(pds)) visited.append(cv.visit(roledecllist_)) visited.append(cv.visit(body)) # rebuild using new children return util.antlr_dupnode_and_replace_children(node_, visited)
def project(projector, node_): localtarget = projector.local_target subprotos = projector.subprotocols target_localmodulename = localtarget[:localtarget.rfind('.')] # Can also derive from (global) node_ decl = projector.nf.moduledecl(target_localmodulename) imports = [] payloads = [] lpd = projector.context.get_projection(localtarget) subprotos = projector.collect_subprotocols(projector.context, lpd.get_body().get_block()) module_refs = [] for sp in subprotos: module_refs.append( util.get_global_module_name_from_projected_member_name(sp)) for id in get_importdecl_children(node_): if util.get_node_type(id) == constants.IMPORT_MODULE_NODE_TYPE: if importmodule_get_full_name(id) in module_refs: tmp = projector.visit(id) if tmp != None: imports.append(tmp) else: raise RuntimeError("TODO: " + id) # Additional imports to insert due to co-module protocols being projected # into separate output modules target_globalmodulename = \ util.get_global_module_name_from_projected_member_name(localtarget) # sp is the local subprotocol name for sp in subprotos: if sp != localtarget: gmn = util.get_global_module_name_from_projected_member_name(sp) if gmn == target_globalmodulename: # Subprotocol is a global co-module protocol of the target lmn = util.get_full_module_name_from_full_member_name(sp) im = projector.nf.importmodule(lmn, None) imports.append(im) for ptd in get_payloadtypedecl_children(node_): payloads.append(projector.visit(ptd)) # Creating the local module "shell" return projector.nf.module(decl, imports, payloads, [], [])
def traverse(traverser, node_): # Duplicated from check_wellformedness_visit name = get_name_child(node_) role = get_local_role_child(node_) roledecllist = get_roledecllist_child(node_) pds = get_parameterdecllist_child(node_) body = get_child(node_) traversed = [] traversed.append(name) # No need to traverse traversed.append(role) # No need to traverse if util.get_node_type(pds) == parameterdecllist_EMPTY_PARAMETER_DECL_LIST: traversed.append(pds) else: traversed.append(traverser.traverse(pds)) traversed.append(traverser.traverse(roledecllist)) traversed.append(traverser.traverse(body)) return util.antlr_dupnode_and_replace_children(node_, traversed)
def project(projector, node_): rdl = get_roledecllist_child(node_) rolemap = roledecllist_get_rolemap(rdl) role_ = rolemap[projector.role] if role_ not in get_role_name(node_): return None role_ = rolemap[projector.role] name = get_name(node_) + '_' + role_ pdl = get_parameterdecllist_child(node_) paramdecllist = None if util.get_node_type(pdl) != parameterdecllist_EMPTY_PARAMETER_DECL_LIST: paramdecllist = projector.visit(pdl) roledecllist = projector.visit(get_roledecllist_child(node_)) body = projector.visit(get_child(node_)) local = projector.nf.localprotocoldecl(role_, name, paramdecllist, roledecllist, body) return local
def project(projector, node_): localtarget = projector.local_target subprotos = projector.subprotocols target_localmodulename = localtarget[: localtarget.rfind(".")] # Can also derive from (global) node_ decl = projector.nf.moduledecl(target_localmodulename) imports = [] payloads = [] lpd = projector.context.get_projection(localtarget) subprotos = projector.collect_subprotocols(projector.context, lpd.get_body().get_block()) module_refs = [] for sp in subprotos: module_refs.append(util.get_global_module_name_from_projected_member_name(sp)) for id in get_importdecl_children(node_): if util.get_node_type(id) == constants.IMPORT_MODULE_NODE_TYPE: if importmodule_get_full_name(id) in module_refs: tmp = projector.visit(id) if tmp != None: imports.append(tmp) else: raise RuntimeError("TODO: " + id) # Additional imports to insert due to co-module protocols being projected # into separate output modules target_globalmodulename = util.get_global_module_name_from_projected_member_name(localtarget) # sp is the local subprotocol name for sp in subprotos: if sp != localtarget: gmn = util.get_global_module_name_from_projected_member_name(sp) if gmn == target_globalmodulename: # Subprotocol is a global co-module protocol of the target lmn = util.get_full_module_name_from_full_member_name(sp) im = projector.nf.importmodule(lmn, None) imports.append(im) for ptd in get_payloadtypedecl_children(node_): payloads.append(projector.visit(ptd)) # Creating the local module "shell" return projector.nf.module(decl, imports, payloads, [], [])
def context_visitor_enter(cv, node_): clone = cv.get_context().clone() 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 if mtype == constants.MESSAGE_SIGNATURE_NODE_TYPE: op = clone.get_current_scope() + '.' + messagesignature_get_operator( msg) else: # Not a message signature, should be a sig parameter param = parameter_get_name(msg) op = param # Destination roles for dest in dests: # Section 4.6.8 -- collecting "potential" operators, for parallel # well-formedness Also parameters potential (op is param for sig # parameters) # # Building a conservative set (potential actions, for parallel # well-formedness) clone = clone.add_operator(src, dest, op) #Section 4.6.6 -- destination roles are now "enabled" (if not already) #for action" within the (choice) block if not clone.is_role_enabled(dest): # Because clone is cloned, all previously enabled/disabled is # automatically carried over. but could factor out this aspect from # here and other categories into the sequencing constructor if mtype == constants.MESSAGE_SIGNATURE_NODE_TYPE: clone = clone.enable_role(dest, op) else: # sig parameter clone = clone.enable_role(dest, param) cv.set_context(clone)
def context_visitor_enter(cv, node_): clone = cv.get_context().clone() 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 if mtype == constants.MESSAGE_SIGNATURE_NODE_TYPE: op = clone.get_current_scope() + '.' + messagesignature_get_operator(msg) else: # Not a message signature, should be a sig parameter param = parameter_get_name(msg) op = param # Destination roles for dest in dests: # Section 4.6.8 -- collecting "potential" operators, for parallel # well-formedness Also parameters potential (op is param for sig # parameters) # # Building a conservative set (potential actions, for parallel # well-formedness) clone = clone.add_operator(src, dest, op) #Section 4.6.6 -- destination roles are now "enabled" (if not already) #for action" within the (choice) block if not clone.is_role_enabled(dest): # Because clone is cloned, all previously enabled/disabled is # automatically carried over. but could factor out this aspect from # here and other categories into the sequencing constructor if mtype == constants.MESSAGE_SIGNATURE_NODE_TYPE: clone = clone.enable_role(dest, op) else: # sig parameter clone = clone.enable_role(dest, param) cv.set_context(clone)
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
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
def _enter_moduledecl(self, node_): raise NotImplementedError(util.get_node_type(node_))
def _leave_module(self, node_): raise NotImplementedError(util.get_node_type(node_))
def _leave_globaldo(self, node_): raise NotImplementedError(util.get_node_type(node_))
def _enter_globalinterrupt(self, node_): raise NotImplementedError(util.get_node_type(node_))
def _leave_globalinterruptible(self, node_): raise NotImplementedError(util.get_node_type(node_))
def _enter_globalparallel(self, node_): raise NotImplementedError(util.get_node_type(node_))