Shorter filenames in generated files
@@ -157,7 +157,7 @@ def translate_line_with_insert(file, line_idx, line, indent_str):
adjust_indentation(indenter, line_idx, indent, file)
prepend_append_funname = "prepend" if maybe_pre == "pre" else "append" if maybe_pre == "aft" else ""
- extra_content = f" // ({prepend_append_funname}ed) {file}:{line_idx}\\n" if maybe_pre else ""
+ extra_content = f" // ({prepend_append_funname}ed) {print_file(file)}:{line_idx}\\n" if maybe_pre else ""
_is_escaped, line = split_and_translate(content, extra_content)
@@ -238,6 +238,15 @@ def add_gen_in_def(code_lines, orig_file):
return new_lines
+def print_file(file):
+ nopath = os.path.basename(file)
+ noext = nopath.replace(r'[.].*', '')
+
+ if "noext" in args['filestyle']: return noext
+ if "nopath" in args['filestyle']: return nopath
+ return file
+
+
def translate_file_contents(file, genfile, code, prefix_lines="", add_lines=True, relpath=None):
"""Returns the code transformed into runnable Python code.
Translated are #[generated_code, #=generator_expression and ${var} constructs."""
@@ -288,7 +297,7 @@ generated_code += "// Autogenerated file (from {0} via {2}), do not modify direc
generated_code += "// Generator: T4P4S (https://github.com/P4ELTE/t4p4s/)\\n"
generated_code += "\\n"
-""".format(file, compiler_common.file_indent_str, os.path.relpath(file, relpath) if relpath is not None else file).splitlines()
+""".format(print_file(file), compiler_common.file_indent_str, os.path.relpath(file, relpath) if relpath is not None else file).splitlines()
code_lines = enumerate(code.splitlines())
code_lines = add_gen_in_def(code_lines, file)
@@ -447,6 +456,7 @@ def init_args():
parser.add_argument('-desugared_path', help='Output directory for the compiler\'s files', required=False, default=argparse.SUPPRESS)
parser.add_argument('-desugar_info', help='Markings in the generated source code', required=False, choices=["comment", "pragma", "none"], default="comment")
parser.add_argument('-verbose', help='Verbosity', required=False, default=False, action='store_const', const=True)
+ parser.add_argument('-filestyle', help='Filename style in generated code comments', required=False, default=[], action='append')
parser.add_argument('-beautify', help='Beautification', required=False, default=False, action='store_const', const=True)
parser.add_argument('--p4dbg', help='Debugging', required=False, default=False, action='store_const', const=True)
parser.add_argument('--p4opt', help='Debug option passed to P4-to-JSON compiler', required=False, default=[], action='append')
