def main(argv, otherArg=None): args = _parse_command_line_args(sys.argv) if not args[_SOURCE]: util.report_error("No input file specified.") filepath = args[_SOURCE][0] # The full module name as a string # FIXME: hardcoded to 0-index only importpath = args[_IMPORT_PATH] ext = util.parse_file_extension_from_filepath(filepath) if ext != constants.SCRIBBLE_FILE_EXTENSION: util.report_error("Bad file extension: " + ext) module_ = util.load_file_and_parse_module(filepath) # Returns an antlr3.tree.CommonTree with the module as the root # Section 4.2 -- module dependencies. Load all the modules that the target # module_ may depend on Initial Context is outside of the AST (no # parent/node) -- these fields are initialised on entering the AST from the # root module node context_ = Context(args[_IMPORT_PATH], args[_PAYLOAD_TYPE_PATH]) context_ = load_modules(context_, filepath, module_) # TODO: import members not supported yet # Next passes can do transformations on the raw AST # Insert implicit scopes in each protocol of each module_ context_ = _insert_scopes(context_) # Raw transformations finished; next record individual members (for # convenience -- currently only used by projection; ContextVisitor passes # use visibility) context_ = load_members(context_, filepath, module_) # Context built up to now is the base context. Subsequent ContextVisitor # passes each start from the base Context and build/manipulate the # pass-specific Context as appropriate # Section 4.2 -- well-formedness of primary module. Separately build the # visibility context_ for each dependency (it can be different for each) and # check the well-formedness conditions that must hold for each dependency # checks well-formedness conditions on each in-context_ module (these are # the loaded modules, which are the dependencies of the primary module) _check_wellformedness(context_) # Here the Context has only modules and members loaded, no # visibility built (Context was not retained from well-formedness checking). # The returned context_ holds all the projections context_ = _project_all(context_) # Check reachability at the local protocol level _check_reachability(context_) proto = args[_PROJECT_PROTOCOL] if proto is not None: localrole = args[_PROJECT_ROLE] dir = args[_PROJECT_DIR] #context_ = _project(context_, proto, localrole, dir) _output_projections_to_modules(context_, proto, localrole, dir)
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_