def get_full_name_from_visible_name(context_, globalproto): gpd = context_.get_visible_global(globalproto) if gpd is None: # Should never happen? util.report_error("Bad protocol reference: " + target) module_ = gpd.getParent() modulefullname = moduledecl_get_full_name( module_get_moduledecl_child(module_)) protofullname = modulefullname + '.' + globalprotocoldecl_get_name(gpd) return protofullname
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 _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_
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 get_full_name(node_): return moduledecl_get_full_name(get_moduledecl_child(node_))
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)
def get_full_name(node_): moduledecl_ = module_get_moduledecl_child(node_.getParent()) fmn = moduledecl_get_full_name(moduledecl_) proto = get_name(node_) return fmn + '.' + proto