stfc / PSyclone

Domain-specific compiler and code transformation system for Finite Difference/Volume/Element Earth-system models in Fortran
BSD 3-Clause "New" or "Revised" License
104 stars 27 forks source link

Encapsulate TransformationError reporting functionality #2670

Open sergisiso opened 2 months ago

sergisiso commented 2 months ago

A couple of patterns have emerged to report TransformationErrors

So we end up with something like:

message = (f"My error message without view or debug_string")
if verbose:
    node.append_preceding_comment(message)
raise TransformationError(LazyString(
    lambda: f"{message}, but found:\n{node.debug_string()}"))

We could encapsulate this is a method so that it is a single-liner to call, but also because we could have the message syntax be more predictable, e.g. we may want to prefix all psyclone added comments with a specific identifier and in the future we may want to make the reporting configurable: e.g. comment/logfile/stderr, so it would be good to do in in a single place and not all over the code.