Skip to content

Improved Source File and Code Structure Modelling

Frederik Hennig requested to merge fhennig/source-files into master

Closes #7 (closed) , #4 (closed)

This MR brings a significant refactoring and several extensions to the modelling of source file structure and contents in the SFG IR, as well as to the way these are constructed by the composer internally.

IR

Replace ir.source_components by ir.entities and ir.syntax

  • ir.entities defines C++ code entities independently from their place in the output file syntax. It defines namespaces (including kernel namespaces and the global namespace), functions, kernels, classes and their members (methods, constructors). It also places these entities in parent-child-relationsships.
  • ir.syntax defines the class SfgSourceFile to represent source files. It also contains the representation of the above entities as syntactic objects: namespace blocks (one namespace can have multiple blocks), entity declaration and definition nodes, class body and visibility block nodes.

Context and Composer

  • The context now manages up to two source files (header and implementation)
  • The composer navigates their syntax structure using a cursor
  • sfg.namespace can now be called multiple times and be used as a context manager to enter and exit nested namespaces
  • Remove sfg.define_once since it can no longer reliably check definitions for uniqueness
  • The previously fixed structure "first kernel namespaces, then all the rest" of output files is broken up - syntax elements are now placed in the order they are created in

Generator and Emission

  • Replace the old file printers and emitters with a minimal, entirely syntax-oriented printer
  • Update SourceFileGenerator to prepare the file objects for the context and correctly invoke the printer

Configuration

  • Users can now define a sort key for sorting #includes via the SfgConfig - if one is specified, clang-format header sorting will be automatically disabled
Edited by Frederik Hennig

Merge request reports