Ejemplo n.º 1
0
    def test_ParseFile(self):

        includepath_map = cache_basics.MapToIndex()
        canonical_path = cache_basics.CanonicalPath()
        parse_file_obj = parse_file.ParseFile(includepath_map)

        symbol_table = {}
        self.assertEqual(
            parse_file_obj.Parse("test_data/more_macros.c", symbol_table),
            ([], [], ['TEMPLATE_VARNAME(foo)'], []))
        self.assertEqual(symbol_table.keys(), [
            'ILLFORMED', 'AS_STRING_INTERNAL', 'TEMPLATE_VARNAME', 'AS_STRING'
        ])
        [([arg], val)] = symbol_table['TEMPLATE_VARNAME']
        self.assertEqual(arg, '_filename_')
        self.assertEqual(val, 'AS_STRING(maps/_filename_.tpl.varnames.h)')

        self.assertEqual(
            parse_file_obj.Parse("test_data/computed_includes.c",
                                 symbol_table), ([], [], ['A', 'm(abc)'], []))
        self.assertEqual(symbol_table['A'], ['"p1.h"'])
        [val] = symbol_table['ILLFORMED']
        self.assertEqual(
            val, "(_filename_,(x))   " +
            "AS_STRING(maps/_filename_.tpl.varnames.h, " +
            "NOTHANDLED(_filename_))")
Ejemplo n.º 2
0
  def _InitializeAllCaches(self):
    # Make cache for parsed files.
    self.file_cache = {}
    # Make table for symbols in #define's.
    self.symbol_table = {}
    # Erect the edifice of caches.
    caches = self.caches = (
        cache_basics.SetUpCaches(self.client_root_keeper.client_root))

    # Migrate the cache stuff to self namespace.
    self.includepath_map = caches.includepath_map
    self.directory_map = caches.directory_map
    self.realpath_map = caches.realpath_map

    self.canonical_path = caches.canonical_path
    self.dirname_cache = caches.dirname_cache
    self.compiler_defaults = caches.compiler_defaults
    self.systemdir_prefix_cache = caches.systemdir_prefix_cache

    self.simple_build_stat = caches.simple_build_stat
    self.build_stat_cache = caches.build_stat_cache

    self.IsIncludepathIndex = caches.IsIncludepathIndex
    self.IsSearchdirIndex = caches.IsSearchdirIndex
    self.IsCurrdirIndex = caches.IsCurrdirIndex
    self.IsRealpathIndex = caches.IsRealpathIndex
    self.IsFilepathPair = caches.IsFilepathPair

    # Make a cache for the symbolic links encountered; also for their
    # replication into root directory.
    self.mirror_path = mirror_path.MirrorPath(self.simple_build_stat,
                                              self.canonical_path,
                                              self.realpath_map,
                                              self.systemdir_prefix_cache)
    # Make a parser for C/C++.
    self.parse_file = parse_file.ParseFile(self.includepath_map)
    # Make a compressor for source files.
    self.compress_files = compress_files.CompressFiles(self.includepath_map,
                                                       self.directory_map,
                                                       self.realpath_map,
                                                       self.mirror_path)
    # A fast cache for avoiding calls into the mirror_path object.
    self.mirrored = set([])

    # For statistics only. We measure the different search lists
    # (search paths) by accumulating them all in sets.
    self.quote_dirs_set = set([]) # quote search lists
    self.angle_dirs_set = set([]) # angle searchlists
    self.include_dir_pairs = set([]) # the pairs (quote search list,
Ejemplo n.º 3
0
    def test_ResolveExpr(self):
        # Erect the edifice of caches.
        caches = cache_basics.SetUpCaches(self.tmp)
        parse_file_obj = parse_file.ParseFile(caches.includepath_map)

        symbol_table = {}
        # Set up symbol_table by parsing test_data/more_macros.c.
        self.assertEqual(
            parse_file_obj.Parse("test_data/more_macros.c", symbol_table),
            ([], [], ['TEMPLATE_VARNAME(foo)'], []))

        # Check what we got in symbol_table.
        self.assertEqual(
            macro_eval.EvalExpression("TEMPLATE_VARNAME(foo)", symbol_table),
            set([
                'TEMPLATE_VARNAME(foo)', '"maps/foo.tpl.varnames.h"',
                'AS_STRING(maps/foo.tpl.varnames.h)',
                'AS_STRING_INTERNAL(maps/foo.tpl.varnames.h)'
            ]))

        # Verify that resolving this expression yields one actual file (which we
        # have placed in test_data/map).
        [((d, ip), rp)], symbols = macro_eval.ResolveExpr(
            caches.includepath_map.Index,
            caches.build_stat_cache.Resolve,
            'TEMPLATE_VARNAME(foo)',
            caches.directory_map.Index(os.getcwd()),  # current dir
            caches.directory_map.Index(""),  # file directory
            [caches.directory_map.Index("test_data")],  # search directory
            [],
            symbol_table)
        self.assertEqual(caches.directory_map.string[d], "test_data/")
        self.assertEqual(caches.includepath_map.string[ip],
                         "maps/foo.tpl.varnames.h")
        self.assertEqual(
            symbols,
            set([
                'TEMPLATE_VARNAME', 'maps', 'AS_STRING', 'AS_STRING_INTERNAL',
                'tpl', 'varnames', 'h', 'foo'
            ]))