def setUp(self): self.c_parser = Cparser(False)
def main(): if not GUI_CPARSER: print "Wrong cparser imported:" exit() print "Starting generation..." parser = ArgumentParser() parser.add_argument("-d", "--dir", dest="directory", action="append", help="Source C-files to introspect", required=True) parser.add_argument("-o", "--outdir", dest="outdir", action="store", help="Output directory", required=True) parser.add_argument("-t", "--typedefs", dest="typedefs", action="store", help="Additional typedefs for parser") parser.add_argument("-X", "--xmldir", dest="xmldir", default = sys.path, action="append", help="Directory to search for parent classes's XMLs") parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Verbose output") args = parser.parse_args() verbose_print = None if args.verbose is True: verbose_print = verbose_true else: verbose_print = verbose_false directories = [] outdir = "" typedefs = "" xmldir = [] directories = abs_path_get(args.directory) outdir = abs_path_get([args.outdir])[0] if args.xmldir is not None: xmldir = abs_path_get(args.xmldir, False)# not abort if dir doesn't exist if args.typedefs != None: typedefs = abs_path_get([args.typedefs])[0] files = dir_files_get(directories) c_files = filter(isC, files) h_files = filter(isH, files) cp = Cparser(args.verbose) cp.outdir_set(outdir) #adding typedefs from extern file if typedefs: cp.typedefs_add(typedefs) #fetching data from c-file for f in c_files: # cp.c_file_data_get(f) cp.c_file_data_get2(f) #fetching data from h-file for f in h_files: cp.h_file_data_get(f) #remove records, which are not class, t.e. they don't have GET_FUNCTION key cl_data_tmp = dict(cp.cl_data) #deep copy of dictionary for k in cl_data_tmp: if const.GET_FUNCTION not in cp.cl_data[k]: print "Warning: no define for class: %s. Record will be excluded from tree"%k cp.cl_data.pop(k) del cl_data_tmp #mapping #defines, comments(@def) and op_ids together, to parse parameters for k in cp.cl_data: cp.parse_op_func_params(k) #cp.print_data() tup = cp.gui_parser_data_get() cp.typedef_file_create(tup) del cp
class testP(unittest.TestCase): def setUp(self): self.c_parser = Cparser(False) def test_fetch_data(self): f = open('test_data.in', 'r') s = f.read() f.close() class_def_answer = {"class_get" : ["parent", ["brother"], "test_class_name", "EO_CLASS_TYPE_REGULAR", ["ELM_OBJ_PAN_BASE_ID", [("ELM_OBJ_PAN_SUB_ID_POS_SET", "pos_set"), ("ELM_OBJ_PAN_SUB_ID_POS_GET", "pos_get")], "ELM_OBJ_PAN_SUB_ID_LAST"], ["EO_EV_CALLBACK_ADD", "EO_EV_CALLBACK_DEL", "EO_EV_DEL"] ]} answer = class_def_answer ret = self.c_parser.fetch_data(s) self.assertEqual(ret, answer) def test_isC(self): self.assertTrue(isC("abc.c")) self.assertTrue(isC("abc.cc")) self.assertTrue(isC("abc.cpp")) self.assertFalse(isC("abc.cp")) self.assertFalse(isC("abc.def.c")) self.assertTrue(isC("/abc/def/file.c")) self.assertTrue(isC("/abc/def2.7/file.c")) def test_isH(self): self.assertTrue(isH("abc.h")) self.assertFalse(isH("abc.c")) self.assertFalse(isH("abc.def.h")) self.assertTrue(isH("/abc/def/file.h")) self.assertTrue(isH("/abc/def2.7/file.h")) def test_isXML(self): self.assertTrue(isXML("abc.xml")) self.assertFalse(isXML("abc.h")) self.assertFalse(isXML("abc.qwe.xml")) self.assertTrue(isXML("/abc/def/abc.xml")) self.assertTrue(isXML("/abc/py2.7/abc.xml")) def test_abs_path_get(self): _in = "test_data.in" _in_list = [_in] _out = _in _out = os.path.expanduser(_out) _out = os.path.abspath(_out) self.assertEqual(abs_path_get(_in_list), [_out]) def test_normalize_names(self): _in = ["hello world", "elm_Box", "evas Object-SmaRt", "EvAs-common InTeRface"] _out = ["HelloWorld", "ElmBox", "EvasObjectSmart", "EvasCommonInterface"] self.assertEqual(normalize_names(_in), _out) def test_get_param_dir_from_comment(self): s = """ @param[in,out] a @param[in] a @param[out] a parem[in] @param [in] a @param [out] a @param[in, out] a @param in @param [ in ] @param [ out, in ] @param sdf [ out ] """ _out = ["in,out", "in", "out", "in", "out", "in,out", "in,out", "in", "in,out", "in,out"] ret = self.c_parser.get_param_dir_from_comment(s) self.assertEqual(ret, _out)
def main(): parser = ArgumentParser() parser.add_argument( "-d", "--dir", dest="directory", action="append", help="Source C-files to introspect", required=True ) parser.add_argument("-o", "--outdir", dest="outdir", action="store", help="Output directory", required=True) parser.add_argument("-t", "--typedefs", dest="typedefs", action="store", help="Additional typedefs for parser") parser.add_argument( "-X", "--xmldir", dest="xmldir", default=sys.path, action="append", help="Directory to search for parent classes's XMLs", ) parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Verbose output") args = parser.parse_args() verbose_print = None if args.verbose is True: verbose_print = verbose_true else: verbose_print = verbose_false directories = [] outdir = "" typedefs = "" xmldir = [] directories = abs_path_get(args.directory) outdir = abs_path_get([args.outdir])[0] if args.xmldir is not None: xmldir = abs_path_get(args.xmldir, False) # not abort if dir doesn't exist if args.typedefs != None: typedefs = abs_path_get([args.typedefs])[0] files = dir_files_get(directories) c_files = filter(isC, files) h_files = filter(isH, files) cp = Cparser(args.verbose) cp.outdir_set(outdir) # adding typedefs from extern file if typedefs: cp.typedefs_add(typedefs) # fetching data from c-file for f in c_files: # cp.c_file_data_get(f) cp.c_file_data_get2(f) # fetching data from h-file for f in h_files: cp.h_file_data_get(f) # remove records, which are not class, t.e. they don't have GET_FUNCTION key cl_data_tmp = dict(cp.cl_data) # deep copy of dictionary for k in cl_data_tmp: if const.GET_FUNCTION not in cp.cl_data[k]: print "Warning: no define for class: %s. Record will be excluded from tree" % k cp.cl_data.pop(k) del cl_data_tmp # mapping #defines, comments(@def) and op_ids together, to parse parameters for k in cp.cl_data: cp.parse_op_func_params(k) # creating list of all parents for classes which are in tree list_of_parents = [] for k in cp.cl_data: list_of_parents += cp.cl_data[k][const.PARENTS] list_of_parents = list(set(list_of_parents)) # checking, if we need to find any parent and filtering it's ids cl_data_tmp2 = dict(cp.cl_data) parents_to_find = filter(lambda ll: True if ll not in cl_data_tmp2 else False, list_of_parents) # if we have parents to find if len(parents_to_find) != 0: if len(xmldir) == 0: print "No XML directory was provided" verbose_print("xmldir: %s\n" % xmldir) xml_files = dir_files_get(xmldir) xml_files = filter(isXML, xml_files) if len(xml_files) == 0: print "ERROR: no include files found for %s classes... Aborting..." % ",".join(parents_to_find) exit(1) # parsing include XMLs xp = XMLparser() for f in xml_files: xp.parse(f) # saving data about parents we were looking for for n, o in xp.objects.items(): if o.macro in parents_to_find: cp.cl_incl[o.macro] = {const.MODULE: o.mod_name, const.C_NAME: o.c_name} i = parents_to_find.index(o.macro) parents_to_find.pop(i) del xp # if there are still parents, which we need to find - exit if len(parents_to_find) != 0: print "ERROR: XML files weren't found for %s classes... Aborting" % (",".join(parents_to_find)) exit(1) # building XMLs for k in cp.cl_data: cp.build_xml(k) del cp