Beispiel #1
0
 def find_override(self):
     SIXMOZ_logger.print_info("Stage 4/6: Finding methods to override")
     for cppclass in self.good_classes:
         for inherit in cppclass.inherits:
             inhname = inherit
             inherit = self.is_a_class(inherit)
             if (inherit):
                 SIXMOZ_logger.print_debug(cppclass.name + " inherits " + inherit.name)
                 for inhmeths in inherit.meths:
                     SIXMOZ_logger.print_debug("1: " + inherit.name + "::" + inhmeths[0])
                     for classfuncs in cppclass.funcs:
                         SIXMOZ_logger.print_debug("2: " + inherit.name + "::" + inhmeths[0] \
                                         + " " + cppclass.name + "::" + classfuncs[0])
                         if inhmeths[0] == classfuncs[0]:
                             cppclass.Ofuncs.append(classfuncs + [ inherit.name ])
                             SIXMOZ_logger.print_debug("OVERRIDE2: " + inherit.name + "::" + inhmeths[2] \
                                             + " and " + cppclass.name + "::" + classfuncs[2])
                             break
                     for classmeths in cppclass.meths:
                         SIXMOZ_logger.print_debug("3: " + inherit.name + "::" + inhmeths[0] \
                                         + " " + cppclass.name + "::" + classmeths[0])
                         if inhmeths[0] == classmeths[0]:
                             cppclass.Omeths.append(classmeths + [ inherit.name ])
                             SIXMOZ_logger.print_debug("OVERRIDE3: " + inherit.name + "::" + inhmeths[2] \
                                             + " line [" + str(inhmeths[3]) + "]" \
                                             + " and " + cppclass.name + "::" + classmeths[2] + " line [" + str(classmeths[3]) + "]")
                             break
             else:
                 SIXMOZ_logger.print_debug("Inherit Error: " + inhname + " not found for " + cppclass.name)
Beispiel #2
0
 def add_moz_override(self):
     SIXMOZ_logger.print_info("Stage 5/6: Adding " + SIXMOZ_rules.get_conf('to_add') + " to files")
     for cppclass in self.classes:
         for classOmeths in cppclass.Omeths:
             modify_file(cppclass.filename, cppclass.name, classOmeths[3], classOmeths[2])
         for classOfuncs in cppclass.Ofuncs:
             modify_file(cppclass.filename, cppclass.name, classOfuncs[3], classOfuncs[2])
Beispiel #3
0
 def run(self):
     SIXMOZ_logger.print_info("Stage */6: Managing Typedef's")
     local_classes = []
     chunk_size = 50
     if (chunk_size > len(self.classes)):
         chunk_size = int(len(self.classes) / SIXMOZ_options.workers)
     if (chunk_size == 0):
         chunk_size = 1
     listes = list(chunks(self.classes, int(len(self.classes) / chunk_size)))
     #depends on issue #19 need to reduce memory usage
     workers = SIXMOZ_options.workers
     if (workers > 1):
         workers = 2
     with concurrent.futures.ProcessPoolExecutor(max_workers=workers) as executor:
         future_task = {executor.submit(manage_typedefs, self.classes, liste): liste for liste in listes}
         for future in concurrent.futures.as_completed(future_task):
             try:
                 local_classes.extend(future.result())
             except Exception as exc:
                 print('Worker generated an exception: %s' % (exc))
                 continue
     self.classes = local_classes
     self.good_classes = [ elem for elem in self.classes if elem.filename in SIXMOZ_files.get_files() ]
     print("")
     self.writer = SIXMOZ_writer(self.classes)
     self.add_full_heritage()
     self.find_override()
     self.writer.run()
Beispiel #4
0
 def __find_files():
     SIXMOZ_logger.print_info("Stage 1/6: Getting files to parse: %s" %
                              SIXMOZ_options.path)
     files = subprocess.check_output("find " + SIXMOZ_options.path +
                                     " -type f -readable " +
                                     SIXMOZ_rules.get_conf('extensions') +
                                     " -or -name \"*.cpp\" | sort",
                                     shell=True).decode().split("\n")
     return (files)
Beispiel #5
0
 def add_moz_override(self):
     SIXMOZ_logger.print_info("Stage 5/6: Adding " +
                              SIXMOZ_rules.get_conf('to_add') + " to files")
     for cppclass in self.classes:
         for classOmeths in cppclass.Omeths:
             modify_file(cppclass.filename, cppclass.name, classOmeths[3],
                         classOmeths[2])
         for classOfuncs in cppclass.Ofuncs:
             modify_file(cppclass.filename, cppclass.name, classOfuncs[3],
                         classOfuncs[2])
Beispiel #6
0
 def __find_idl_files():
     idl_files = []
     if (SIXMOZ_options.idl_folder != ""):
         if (not os.path.exists(SIXMOZ_options.idl_folder)):
             print("Options -I %s doesn't not exist" %
                   SIXMOZ_options.idl_folder)
             sys.exit(1)
         SIXMOZ_logger.print_info("Getting Files from idl_folder: " +
                                  SIXMOZ_options.idl_folder)
         idl_files = subprocess.check_output(
             "find " + SIXMOZ_options.idl_folder +
             " -type f -readable \( " +
             SIXMOZ_rules.get_conf('extensions') +
             " \) -and -not -path \"" + SIXMOZ_options.path + "*\" | sort",
             shell=True).decode().split("\n")
     return (idl_files)
Beispiel #7
0
def add_attributes():
    SIXMOZ_logger.print_info("Stage 6/6: Adding Attributes.h")
    for filename in SIXMOZ_stats.mod_files:
        if (filename[-4:] != ".cpp"):
            liste = open(filename, "r").readlines()
            first = 0
            for li in liste:
                if (li.find("Attributes.h") != -1 and li.find("#include ") != -1):
                    first = 1
            content = ""
            if (first == 0):
                for li in liste:
                    if (li.find("#include") != -1 and first == 0):
                        content += '#include "mozilla/Attributes.h"\n'
                        first = 1
                    content += li
                SIXMOZ_logger.dryrun(filename, content)
Beispiel #8
0
    def display(self, classes, files, idl_files):
        virt_missed = 0
        meth_missed = 0
        firstprint = 0

        SIXMOZ_logger.print_verbose("")
        SIXMOZ_logger.print_verbose("Statistics")
        for cppclass in classes:
            for classOmeths in cppclass.Omeths:
                tmp = cppclass.name + "::" + classOmeths[2]
                if tmp not in self.overrided:
                    if firstprint == 0:
                        firstprint = 1
                        SIXMOZ_logger.print_verbose("NOT OVERRIDED!!!:")
                    virt_missed += 1
                    SIXMOZ_logger.print_verbose(cppclass.filename + "\t" \
                                  + "M " + tmp + "\t%d" % classOmeths[3])
            for classOfuncs in cppclass.Ofuncs:
                tmp = cppclass.name + "::" + classOfuncs[2]
                if tmp not in self.overrided:
                    if firstprint == 0:
                        firstprint = 1
                        SIXMOZ_logger.print_verbose("NOT OVERRIDED!!!:")
                    meth_missed += 1
                    SIXMOZ_logger.print_verbose(cppclass.filename + "\t" \
                                  + "F " + tmp + "\t%d" % classOfuncs[3])

        self.display_base(classes, files, idl_files)
        SIXMOZ_logger.print_verbose("Methods " +
                                    SIXMOZ_rules.get_conf('to_add') +
                                    " @Begin: " + self.begin)
        SIXMOZ_logger.print_info("Overrided %d methods" %
                                 len(set(self.real_overrided)))
        SIXMOZ_logger.print_verbose("Final Modified Meths: %d" %
                                    self.modified_meths)
        SIXMOZ_logger.print_verbose("Still Missing %d methods" % virt_missed)
        SIXMOZ_logger.print_verbose("Still Missing %d member functions" %
                                    meth_missed)
        output = subprocess.check_output(
            "find " + SIXMOZ_options.path + " -type f -readable " +
            SIXMOZ_rules.get_conf('extensions') +
            " -or -name \"*.cpp\" | xargs grep " +
            SIXMOZ_rules.get_conf('to_add') + " | wc -l",
            shell=True).decode()
        SIXMOZ_logger.print_info(
            SIXMOZ_rules.get_conf('to_add') + " Methods in Code: " + output)
Beispiel #9
0
def add_attributes():
    SIXMOZ_logger.print_info("Stage 6/6: Adding Attributes.h")
    for filename in SIXMOZ_stats.mod_files:
        if (filename[-4:] != ".cpp"):
            liste = open(filename, "r").readlines()
            first = 0
            for li in liste:
                if (li.find("Attributes.h") != -1
                        and li.find("#include ") != -1):
                    first = 1
            content = ""
            if (first == 0):
                for li in liste:
                    if (li.find("#include") != -1 and first == 0):
                        content += '#include "mozilla/Attributes.h"\n'
                        first = 1
                    content += li
                SIXMOZ_logger.dryrun(filename, content)
Beispiel #10
0
 def add_full_heritage(self):
     SIXMOZ_logger.print_info("Stage 3/6: Creating Heritage Tree")
     change = 1
     while (change == 1):
         change = 0
         for cppclass in self.good_classes:
             for simple_inherits in cppclass.inherits:
                 test_inh = self.is_a_class(str(cppclass.namespace + simple_inherits))
                 if (test_inh and not self.is_a_class(simple_inherits)):
                     simple_inherits = test_inh
                 else:
                     simple_inherits = self.is_a_class(simple_inherits)
                 if (simple_inherits):
                     for hidden_inherits in simple_inherits.inherits:
                         if (self.is_a_class(hidden_inherits) and hidden_inherits not in cppclass.inherits and hidden_inherits != cppclass.name):
                             SIXMOZ_logger.print_debug("Class: " + cppclass.name + " inherits " + hidden_inherits)
                             cppclass.inherits.append(hidden_inherits)
                             change = 1
                         else:
                             SIXMOZ_logger.print_debug("OTHER: " + cppclass.name + " inherits " + hidden_inherits)
Beispiel #11
0
 def parse_header_files(self):
     SIXMOZ_logger.print_info("Stage 2/6: Parsing Header Files")
     nb_files = len(self.files) + len(self.idl_files)
     files = self.files + self.idl_files
     self.classes = []
     saveout = sys.stdout
     chunk_size = 50
     if (chunk_size > len(files)):
         chunk_size = int(len(files) / SIXMOZ_options.workers)
     if (chunk_size == 0):
         chunk_size = 1
     listes = list(chunks(files, int(len(files) / chunk_size)))
     with concurrent.futures.ProcessPoolExecutor(max_workers=SIXMOZ_options.workers) as executor:
         future_task = {executor.submit(do_parse, liste, len(files)): liste for liste in listes}
         for future in concurrent.futures.as_completed(future_task):
             try:
                 self.classes.extend(future.result())
             except Exception as exc:
                 sys.stdout = saveout
                 print('Worker generated an exception: %s' % (exc))
                 continue
     sys.stdout = saveout
Beispiel #12
0
    def display(self, classes, files, idl_files):
        virt_missed = 0
        meth_missed = 0
        firstprint = 0

        SIXMOZ_logger.print_verbose("")
        SIXMOZ_logger.print_verbose("Statistics")
        for cppclass in classes:
            for classOmeths  in cppclass.Omeths:
                tmp = cppclass.name + "::" +  classOmeths[2]
                if tmp not in self.overrided:
                    if firstprint == 0:
                        firstprint = 1
                        SIXMOZ_logger.print_verbose("NOT OVERRIDED!!!:")
                    virt_missed += 1
                    SIXMOZ_logger.print_verbose(cppclass.filename + "\t" \
                                  + "M " + tmp + "\t%d" % classOmeths[3])
            for classOfuncs in cppclass.Ofuncs:
                tmp = cppclass.name + "::" + classOfuncs[2]
                if tmp not in self.overrided:
                    if firstprint == 0:
                        firstprint = 1
                        SIXMOZ_logger.print_verbose("NOT OVERRIDED!!!:")
                    meth_missed += 1
                    SIXMOZ_logger.print_verbose(cppclass.filename + "\t" \
                                  + "F " + tmp + "\t%d" % classOfuncs[3])

        self.display_base(classes, files, idl_files)
        SIXMOZ_logger.print_verbose("Methods " + SIXMOZ_rules.get_conf('to_add') + " @Begin: " + self.begin)
        SIXMOZ_logger.print_info("Overrided %d methods" % len(set(self.real_overrided)))
        SIXMOZ_logger.print_verbose("Final Modified Meths: %d" % self.modified_meths)
        SIXMOZ_logger.print_verbose("Still Missing %d methods" % virt_missed)
        SIXMOZ_logger.print_verbose("Still Missing %d member functions" % meth_missed)
        output = subprocess.check_output("find " + SIXMOZ_options.path + " -type f -readable " +
                                         SIXMOZ_rules.get_conf('extensions') +
                                         " -or -name \"*.cpp\" | xargs grep " +
                                         SIXMOZ_rules.get_conf('to_add') + " | wc -l", shell=True).decode()
        SIXMOZ_logger.print_info(SIXMOZ_rules.get_conf('to_add') + " Methods in Code: " + output)