<commit_before>#!/usr/bin/python

import sys
import CppHeaderParser

from logger import SIXMOZ_logger
from rules import SIXMOZ_rules
from options import SIXMOZ_options
from writer import SIXMOZ_writer
import parser_func

class SIXMOZ_parser():
    def __init__(self, files, idl_files):
        self.classes = {}
        self.files = files
        self.idl_files = idl_files
        CppHeaderParser.ignoreSymbols += SIXMOZ_rules.to_ignore

    def init(self):
        self.parse_header_files()
        self.writer = SIXMOZ_writer(self.classes)
        return (self.classes)

    def run(self):
        self.manage_typedefs()
        self.add_full_heritage()
        self.find_override()
        self.writer.run()

    def manage_typedefs(self):
        SIXMOZ_logger.print_info("Stage */6: Managing Typedef's")
        for classname in self.classes:
            for name in self.classes[classname]['typedefs']:
                for nclassname in self.classes:
                    for inh in self.classes[nclassname]['inherits']:
                        if inh == name and self.classes[classname]['typedefs'][name] not in self.classes[nclassname]['inherits']:
                            self.classes[nclassname]['inherits'].append(self.classes[classname]['typedefs'][name])
                            SIXMOZ_logger.print_debug(classname + " typedef inherits: " + self.classes[classname]['typedefs'][name])
                            break

    ## @brief creates the heritage tree for all methods
    ## @param self.classes dict of all self.classes
    #  classname string
    ## @returns void
    def find_override(self):
        SIXMOZ_logger.print_info("Stage 4/6: Finding methods to override")
        for classname in self.classes:
            for j in range(len(self.classes[classname]['inherits'])):
                if (self.classes[classname]['inherits'][j] in self.classes):
                    SIXMOZ_logger.print_debug(classname + " inherits " + self.classes[classname]['inherits'][j])
                    for m in self.classes[self.classes[classname]['inherits'][j]]['meths']:
                        SIXMOZ_logger.print_debug("1: " + self.classes[classname]['inherits'][j] + "::" + self.classes[self.classes[classname]['inherits'][j]]['meths'][m][0])
                        for l in self.classes[classname]['funcs']:
                            SIXMOZ_logger.print_debug("2: " + self.classes[classname]['inherits'][j] + "::" + self.classes[self.classes[classname]['inherits'][j]]['meths'][m][0] \
                                            + " " + classname + "::" + self.classes[classname]['funcs'][l][0])
                            if self.classes[self.classes[classname]['inherits'][j]]['meths'][m][0] == self.classes[classname]['funcs'][l][0]:
                                self.classes[classname]['Ofuncs'][len(self.classes[classname]['Ofuncs'])] = self.classes[classname]['funcs'][l]
                                SIXMOZ_logger.print_debug("OVERRIDE2: " + self.classes[classname]['inherits'][j] + "::" + self.classes[self.classes[classname]['inherits'][j]]['meths'][m][2] \
                                                + " and " + classname + "::" + self.classes[classname]['funcs'][l][2])
                                break
                        for l in self.classes[classname]['meths']:
                            SIXMOZ_logger.print_debug("3: " + self.classes[classname]['inherits'][j] + "::" + self.classes[self.classes[classname]['inherits'][j]]['meths'][m][0] \
                                            + " " + classname + "::" + self.classes[classname]['meths'][l][0])
                            if self.classes[self.classes[classname]['inherits'][j]]['meths'][m][0] == self.classes[classname]['meths'][l][0]:
                                self.classes[classname]['Omeths'][len(self.classes[classname]['Omeths'])] = self.classes[classname]['meths'][l]
                                SIXMOZ_logger.print_debug("OVERRIDE3: " + self.classes[classname]['inherits'][j] + "::" + self.classes[self.classes[classname]['inherits'][j]]['meths'][m][2] \
                                                + " line [" + str(self.classes[self.classes[classname]['inherits'][j]]['meths'][m][3]) + "]" \
                                                + " and " + classname + "::" + self.classes[classname]['meths'][l][2] + " line [" + str(self.classes[classname]['meths'][l][3]) + "]")
                                break

    def add_full_heritage(self):
        SIXMOZ_logger.print_info("Stage 3/6: Creating Heritage Tree")
        self.add_heritage_it()

    def add_heritage_it(self):
        change = 1
        while (change == 1):
            change = 0
            for classname in self.classes:
                add = set(self.classes[classname]['inherits'])
                for simple_inherits in self.classes[classname]['inherits']:
                    if (str(self.classes[classname]['namespace'] + simple_inherits) in self.classes and simple_inherits not in self.classes):
                        simple_inherits = str(self.classes[classname]['namespace'] + simple_inherits)
                    if (simple_inherits in self.classes):
                        for hidden_inherits in self.classes[simple_inherits]['inherits']:
                            if (hidden_inherits in self.classes and hidden_inherits not in self.classes[classname]['inherits'] and hidden_inherits != classname):
                                add.add(hidden_inherits)<commit_msg>Fix issue #11 add debug log when inheriting base class isn't found<commit_after>#!/usr/bin/python

import sys
import CppHeaderParser

from logger import SIXMOZ_logger
from rules import SIXMOZ_rules
from options import SIXMOZ_options
from writer import SIXMOZ_writer
import parser_func

class SIXMOZ_parser():
    def __init__(self, files, idl_files):
        self.classes = {}
        self.files = files
        self.idl_files = idl_files
        CppHeaderParser.ignoreSymbols += SIXMOZ_rules.to_ignore

    def init(self):
        self.parse_header_files()
        self.writer = SIXMOZ_writer(self.classes)
        return (self.classes)

    def run(self):
        self.manage_typedefs()
        self.add_full_heritage()
        self.find_override()
        self.writer.run()

    def manage_typedefs(self):
        SIXMOZ_logger.print_info("Stage */6: Managing Typedef's")
        for classname in self.classes:
            for name in self.classes[classname]['typedefs']:
                for nclassname in self.classes:
                    for inh in self.classes[nclassname]['inherits']:
                        if inh == name and self.classes[classname]['typedefs'][name] not in self.classes[nclassname]['inherits']:
                            self.classes[nclassname]['inherits'].append(self.classes[classname]['typedefs'][name])
                            SIXMOZ_logger.print_debug(classname + " typedef inherits: " + self.classes[classname]['typedefs'][name])
                            break

    ## @brief creates the heritage tree for all methods
    ## @param self.classes dict of all self.classes
    #  classname string
    ## @returns void
    def find_override(self):
        SIXMOZ_logger.print_info("Stage 4/6: Finding methods to override")
        for classname in self.classes:
            for j in range(len(self.classes[classname]['inherits'])):
                if (self.classes[classname]['inherits'][j] in self.classes):
                    SIXMOZ_logger.print_debug(classname + " inherits " + self.classes[classname]['inherits'][j])
                    for m in self.classes[self.classes[classname]['inherits'][j]]['meths']:
                        SIXMOZ_logger.print_debug("1: " + self.classes[classname]['inherits'][j] + "::" + self.classes[self.classes[classname]['inherits'][j]]['meths'][m][0])
                        for l in self.classes[classname]['funcs']:
                            SIXMOZ_logger.print_debug("2: " + self.classes[classname]['inherits'][j] + "::" + self.classes[self.classes[classname]['inherits'][j]]['meths'][m][0] \
                                            + " " + classname + "::" + self.classes[classname]['funcs'][l][0])
                            if self.classes[self.classes[classname]['inherits'][j]]['meths'][m][0] == self.classes[classname]['funcs'][l][0]:
                                self.classes[classname]['Ofuncs'][len(self.classes[classname]['Ofuncs'])] = self.classes[classname]['funcs'][l]
                                SIXMOZ_logger.print_debug("OVERRIDE2: " + self.classes[classname]['inherits'][j] + "::" + self.classes[self.classes[classname]['inherits'][j]]['meths'][m][2] \
                                                + " and " + classname + "::" + self.classes[classname]['funcs'][l][2])
                                break
                        for l in self.classes[classname]['meths']:
                            SIXMOZ_logger.print_debug("3: " + self.classes[classname]['inherits'][j] + "::" + self.classes[self.classes[classname]['inherits'][j]]['meths'][m][0] \
                                            + " " + classname + "::" + self.classes[classname]['meths'][l][0])
                            if self.classes[self.classes[classname]['inherits'][j]]['meths'][m][0] == self.classes[classname]['meths'][l][0]:
                                self.classes[classname]['Omeths'][len(self.classes[classname]['Omeths'])] = self.classes[classname]['meths'][l]
                                SIXMOZ_logger.print_debug("OVERRIDE3: " + self.classes[classname]['inherits'][j] + "::" + self.classes[self.classes[classname]['inherits'][j]]['meths'][m][2] \
                                                + " line [" + str(self.classes[self.classes[classname]['inherits'][j]]['meths'][m][3]) + "]" \
                                                + " and " + classname + "::" + self.classes[classname]['meths'][l][2] + " line [" + str(self.classes[classname]['meths'][l][3]) + "]")
                                break
                else:
                    SIXMOZ_logger.print_debug("Inherit Error: " + self.classes[classname]['inherits'][j] + " not found for " + classname)

    def add_full_heritage(self):
        SIXMOZ_logger.print_info("Stage 3/6: Creating Heritage Tree")
        self.add_heritage_it()

    def add_heritage_it(self):
        change = 1
        while (change == 1):
            change = 0
            for classname in self.classes:
                add = set(self.classes[classname]['inherits'])
                for simple_inherits in self.classes[classname]['inherits']:
                    if (str(self.classes[classname]['namespace'] + simple_inherits) in self.classes and simple_inherits not in self.classes):
                        simple_inherits = str(self.classes[classname]['namespace'] + simple_inherits)
                    if (simple_inherits in self.classes):
                        for hidden_inherits in self.classes[simple_inherits]['inherits']:
                            if (hidden_inherits in self.classes and hidden_inherits not in self.classes[classname]['inherits'] and hidden_inherits != classname):
                                add.add(hidden_inherits)
{'fraction_non_alphanumeric': 0.14764921045588367, 'fraction_numerical': 0.005174413417789276, 'mean_word_length': 2.2644146767617936, 'pattern_counts': {'":': 18, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1021845', 'n_tokens_mistral': 3291, 'n_tokens_neox': 3218, 'n_words': 498}