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 _add_module_and_get_dependencies(context_, filepath, current): # Section 4.2 -- Simple moduledecl name and filename of module # # Move to well-formedness? (Currently also checked for well-formed # moduledecl, but commenting this line here causes some problems for # mutually recursive imports -- should debug this) moduledecl_ = module_get_moduledecl_child(current) moduledecl_check_file_name(filepath, moduledecl_) fmn = moduledecl_get_full_name(moduledecl_) context_ = context_.add_source(fmn, filepath) # Make a combined add_source and add_module method for Context? (And move the # above name check into there) context_ = context_.add_module(fmn, current) #context_ = _add_all_members(context_, fmn, current) # Done later by memberloader importmodules = module_get_importmodule_children(current) for i in importmodules: fmn = importmodule_get_full_module_name(i) # sources and modules keys should match if fmn not in context_.get_modules().keys(): tmp = util.convert_full_module_name_to_filepath(fmn) filepath = util.search_importpath_for_file(context_.import_path, tmp) module_ = util.load_file_and_parse_module(filepath) # # We found a parseable Scribble module at that file path -- but # module decl not checked yet (checked by well-formedness, along # with other well-formedness conditions) We found a parseable # Scribble module at that file path -- but module decl not checked # yet (checked by well-formedness, along with other well-formedness # conditions) context_ = _add_module_and_get_dependencies(context_, filepath, module_) """importmembers = module.module_get_importmember_children(current) # TODO: member imports""" return context_
def _add_module_and_get_dependencies(context_, filepath, current): # Section 4.2 -- Simple moduledecl name and filename of module # # Move to well-formedness? (Currently also checked for well-formed # moduledecl, but commenting this line here causes some problems for # mutually recursive imports -- should debug this) moduledecl_ = module_get_moduledecl_child(current) moduledecl_check_file_name(filepath, moduledecl_) fmn = moduledecl_get_full_name(moduledecl_) context_ = context_.add_source(fmn, filepath) # Make a combined add_source and add_module method for Context? (And move the # above name check into there) context_ = context_.add_module(fmn, current) #context_ = _add_all_members(context_, fmn, current) # Done later by memberloader importmodules = module_get_importmodule_children(current) for i in importmodules: fmn = importmodule_get_full_module_name(i) # sources and modules keys should match if fmn not in context_.get_modules().keys(): tmp = util.convert_full_module_name_to_filepath(fmn) filepath = util.search_importpath_for_file(context_.import_path, tmp) module_ = util.load_file_and_parse_module(filepath) # # We found a parseable Scribble module at that file path -- but # module decl not checked yet (checked by well-formedness, along # with other well-formedness conditions) We found a parseable # Scribble module at that file path -- but module decl not checked # yet (checked by well-formedness, along with other well-formedness # conditions) context_ = _add_module_and_get_dependencies( context_, filepath, module_) """importmembers = module.module_get_importmember_children(current) # TODO: member imports""" return context_