Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Copyright (C) 2017 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GCC; see the file COPYING3. If not see # <http://www.gnu.org/licenses/>.
# Helpers to implement the "scan-dwarf" check command (see gcc-dwarf.exp)
"""Expand tab characters in `line` into spaces.""" else:
def extract_matchers_from_file(source_file): # no-coverage """ Wrapper around `extract_matchers` to read `source_file`
:param str source_file: Path to the source file to scan. :rtype: list[(int, code-object)] """ with open(source_file, 'r') as f: return extract_matchers(source_file, f.read())
""" Scan `source_file` to find the Python expressions located between ">>>" lines.
For instance, if the source file is a C file that contains::
/* >>> Matcher('DW_TAG_subprogram') Matcher('DW_TAG_structure_type') >>>
This will extract both calls to Matcher and turn them into compiled code that can be executed with `eval`. The result is a list of couples: source line number and code objects.
The source file is expected to contain exactly two ">>>" lines and ">>>" parts must appear on the same column. Then, all the lines in between are required to be a valid sequence of Python expressions, starting on the same column and which evaluate to Matcher instances.
:param str source_file: Path to the source file to scan. :param str lines: Source file content to scan. :rtype: list[(int, code-object)] """
# Make sure there are only two ">>>" lines in this source file ' ">>>"'.format(source_file)) ' same column'.format(source_file)) else:
# Now we have located the >>> pair, extract the code in between, removing # indentation. for line in lines[opening + 1:closing])
# Parse the code chunk. This is supposed to return an ast.Module instance.
# And now compile each individual expression to build the result source_file, lineno ))
""" Run the given matchers against the DIE tree in the given compilation unit.
Check that all matchers succeed using `testutils.check`.
:param list[(int, code-object)] matchers: Matchers to run. This is meant to be the result of `extract_matchers`. """ lineno, type(exc).__name__, str(exc) )) ' was expected'.format(lineno, repr(matcher))) |