2

I have few hundred thousand translation units of raw, but UE decorated C++ like code:

#include "Somefile.h"

class Whatever;

UCLASS(Blueprintable)
class GAME_API USubsystem : public UEngineSubsystem {
    GENERATED_BODY()
public:
// etc
private:
    UPROPERTY(BlueprintReadWrite, EditAnywhere, Transient, meta=(AllowPrivateAccess=true))
    UObject* Data;
}

and the likes. For very specific review/overview purposes only, I need to process the code and sort it in a deterministic ABC order:

  • all includes are in top, sorted
  • all forward type declarations follow includes, sorted as well
  • classes, as whole scoped objects, sorted alphabetically as well, by class name.
  • within classes, property/field declarations sorted by name
  • functions follow them
  • preservation of access modifiers is not required
  • only header files needs to be processed

How can I possibly achieve it, en masse?

Kirikan
  • 119
  • 6
  • Get libclang and start reading the manual. But in general this can't be achieved; forward-declarations don't give you the full freedom on the order. – HolyBlackCat Mar 06 '23 at 19:29
  • Have a look at [Clang-Format](https://clang.llvm.org/docs/ClangFormatStyleOptions.html). – Richard Critten Mar 06 '23 at 19:29
  • I disagree with the closure. OP doesn't ask for a library, they ask how this can be done. Half of the questions here are *answered* with a library suggestion, but we only close questions if they *ask* for a library. – HolyBlackCat Mar 06 '23 at 19:33
  • 1
    I interpreted the use of the `tooling` tag as implicitly asking for recommendations about what tools could be used to effect this. – Nathan Pierson Mar 06 '23 at 19:35
  • @HolyBlackCat • For review/overview purposes. Agreed though that the "mangled" (sorted, collated, folded, stapled) output won't be compile-able. – Eljay Mar 06 '23 at 19:36
  • Well, that escalated quickly. – Kirikan Mar 06 '23 at 20:08
  • @HolyBlackCat What do you mean by "forward-declarations don't give you the full freedom on the order"? I suppose I can drop them, it is not very big deal. – Kirikan Mar 06 '23 at 20:09
  • My point is, the code might not compile after you sort everything, even if everything is forward-declared. – HolyBlackCat Mar 06 '23 at 20:29
  • @HolyBlackCat Oh, nonono, that code is purely for visual review, it is not going into codebase or being compiled. Although that wasn't really the question but nonetheless, since it is closed already - do you know if there are any existing tools that achieve similar OOB? – Kirikan Mar 06 '23 at 22:29
  • Out of the box - no. – HolyBlackCat Mar 07 '23 at 06:13
  • @RichardCritten I examined clang-format but it only can sort includes, that's **all*** – Kirikan Apr 02 '23 at 10:53

0 Answers0