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 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 _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 project(projector, node_): projections = projector.context.get_projections() fmn = get_full_module_name(node_) # Check if this import is referring to one of the subprotocol modules. # "target" is the local target name # # FIXME: make precise about which subprotocols are actually needed (use # SubprotocolCollector again for the current target) for target in projector.subprotocols: gmn = util.get_global_module_name_from_projected_member_name(target) if fmn == gmn: if not has_alias(node_): localmodulename = \ util.get_full_module_name_from_full_member_name(target) return projector.nf.importmodule(localmodulename, None) else: util.report_error("[Projector] importmodule TODO: " + \ get_declaration_name(node_)) #else: # util.report_error("[Projector] importmodule TODO: " + target)""" return None