def _project_all(context_): for _, module_ in context_.get_modules().items(): clone = context_.set_current_module(module_get_full_name(module_)) clone = build_visibility(clone, module_) for (proto, gpd) in clone.get_visible_globals().items(): full_global_name = globalprotocoldecl_get_full_name(gpd) rdl = globalprotocoldecl_get_roledecllist_child(gpd) #rolemap = roledecllist_get_rolemap(rdl) #for role_ in globalprotocoldecl_get_role_names(gpd): for rd in roledecllist_get_roledecl_children(rdl): dname = roledecl_get_declaration_name(rd) role_ = roledecl_get_role_name(rd) full_local_name = globaldo_get_projected_member_name( full_global_name, role_) #full_global_name, rolemap[role_]) if context_.has_projection(full_local_name): break projector = Projector() lpd = projector.project_globalprotocoldecl(clone, gpd, dname)#, rolemap) #full_name = lpd.get_full_name(clone) context_ = context_.add_projection(full_local_name, lpd) #print "Projected", full_global_name, "for", role_ + ":\n", \ # lpd.pretty_print() return context_
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 ' + \