def check_filename(filepath, moduledecl_): smn_from_filepath = util.parse_simple_module_name_from_filepath(filepath) fmn_from_moduledecl = get_full_name(moduledecl_) smn_from_moduledecl = util.get_simple_module_name_from_full_module_name(fmn_from_moduledecl) if smn_from_filepath != smn_from_moduledecl: util.report_error("Bad module declaration/file name: declaration=" + \ smn_from_moduledecl + ", path=" + filepath)
def check_filename(filepath, moduledecl_): smn_from_filepath = util.parse_simple_module_name_from_filepath(filepath) fmn_from_moduledecl = get_full_name(moduledecl_) smn_from_moduledecl = util.get_simple_module_name_from_full_module_name( fmn_from_moduledecl) if smn_from_filepath != smn_from_moduledecl: util.report_error("Bad module declaration/file name: declaration=" + \ smn_from_moduledecl + ", path=" + filepath)
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 build_visibility(context, module_): fullname = moduledecl_get_full_name(module_get_moduledecl_child(module_)) # Build visibility wrt. primary module_ context = context.add_visible_module(fullname, module_) context = _get_module_members(context, fullname, module_) # Section 4.1.1 -- self reference of module_ by simple module_ name smn = util.get_simple_module_name_from_full_module_name(fullname) if fullname != smn: context = context.add_visible_module(smn, module_) #context = _get_module_members(context, smn, module_) # No: members of primary module_ are not accessible via the simple # name of module_ # add on unqualified names for ``local'' module_ entities (i.e.\ for the # primary module_ only) context = _get_self_visibility(context, module_) # Build visibility wrt. imported modules context = _get_imported_modules(context, module_) #context = getImportedMembers(context, module_) # TODO return context
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)
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)