Beispiel #1
0
    def __handle_augments_by_module(self, srcMod):
        all_handled = True
        for aug in srcMod.augments:
            if aug.not_handled():
                all_handled = False
            else:
                continue
            
            #Step1: Split namespace, find root module of xpath
            _aug_tar_node = aug.yinNode.augTarNode
            path_list = []
            for piece in _aug_tar_node.split('/'):
                if len(piece) > 0:
                    path_list.append(piece)

            root_node = path_list[0]
            root_prefix, root_ident = yc.getPrefixAndTag(root_node)
            aug_root = None
            if root_prefix:
                if root_prefix == srcMod.prefix:
                    aug_root = srcMod.find_augment_tree_root(root_ident)
                else:
                    import_mod_name = srcMod.find_import_module_name(root_prefix)
                    temp_mod = self.modules[import_mod_name]
                    aug_root = temp_mod.find_augment_tree_root(root_ident)
            else:
                aug_root = srcMod.find_augment_tree_root(root_ident)
            if not aug_root:
                # The root haven't been generated yet, skip this loop
                continue
            
            #Step2: Check the target-node's xpath has been generated or not
            internal_aug_path = srcMod.convert_internal_augment_path(_aug_tar_node)
            external_aug_path = self.__convert_external_augment_path(internal_aug_path)
            iutil.DEBUG('Trying to find aug<%s> with path...' % _aug_tar_node)
            #for nn in external_aug_path:
            #    iutil.DEBUG(nn)
            tar_yinNode = aug_root.find_by_xpath(external_aug_path)
            if not tar_yinNode:
                # The target node haven't been generated yet, skip this loop
                iutil.DEBUG('Failed!')
                continue
            
            iutil.DEBUG('Success on insert augment<%s>! ' % _aug_tar_node)
            #Step3: Insert augment node
            new_node = yc.clone(aug.yinNode)
            new_node.invisible = False
            tar_yinNode.insertSubNode(new_node)
            #tar_yinNode.stmts = new_node.stmts
            
            # Step4: Target module make a record for source module, should be useless
            #if srcMod.get_name() not in root_mod.beAugmentedBy:
            #    root_mod.beAugmentedBy[srcMod.get_name()] = srcMod
            
            iutil.DEBUG('Success on inserting augment from module<%s> to target-node<%s>' % (srcMod.get_name(), aug.yinNode.augTarNode))
            aug.set_handled()
            
        #End of augment iteration of each module
        return all_handled
Beispiel #2
0
    def __handle_uses(self):
        iutil.TRACE('Now handleing uses...')
        
        # Step1, Link uses with grouping   
        for srcMod in self.modules.itervalues():
            for us in srcMod.uses:
                prefix = us.prefix
                tarModule = None
                if prefix:
                    if srcMod.prefix == prefix:
                        tarModule = srcMod.find_grouping(us.identifier)
                    else:
                        import_mod_name = srcMod.find_import_module_name(prefix)
                        temp_module = self.modules[import_mod_name]
                        tarModule = temp_module.find_grouping(us.identifier)
                else:
                    tarModule = srcMod.find_grouping(us.identifier)
                if not tarModule:
                    iutil.ERROR('Grouping<%s> from <%s> was not found!' % (us.identifier, srcMod.name))
                    continue
                us.tarGroup = tarModule.groupings[us.identifier]
        
        # Step2, collect all grouping and uses
        all_groupings = self.__collect_all_grouping()
        all_uses = self.__collect_all_uses()
        
        total_count = len(all_uses)
        iutil.TRACE('There are %d uses in total' % total_count)
        
        # Step3, handle all uses
        while total_count > 0:
            total_count = total_count - 1
            all_uses = [new_u for new_u in all_uses if new_u.not_handled()]
            
            if not all_uses:
                #iutil.TRACE('All uses were handled!')
                break
            
            for U in all_uses:
                if not U.not_handled():
                    #Already handled
                    iutil.ERROR('Not gonna happen!')
                    continue
                
                if U.tarGroup.any_inside_uses():
                    # target grouping was not yet able to use.
                    continue
                else:
                    # Clone an new grouping tree
                    new_node = yc.clone(U.tarGroup.yinNode)
                    new_node.invisible = False
                    new_node.subtree_brodcast_module_name(U.yinNode.mod_name)
                    # Replace uses leaf with the grouping tree
                    '''
                    U.yinNode.insertSubNode(new_node)
                    '''
                    uses_parent = U.yinNode.parNode
                    new_node.parNode = uses_parent
                    uses_parent.subNodes = [new_node if x == U.yinNode else x for x in uses_parent.subNodes]
                    # Mark this uses as handled
                    U.set_handled()
                    iutil.DEBUG('Success on using grouping<%s>...' % U.identifier)
        
            # Refresh grouping tree status
            for G in all_groupings:
                G.filter_inside_uses()

        if all_uses:
            iutil.ERROR('Not all uses were handled!')
        else:
            iutil.TRACE('All uses have been handled!')