clang-tools 19.0.0git
Classes | Functions
clang::reorder_fields Namespace Reference

Classes

class  ReorderFieldsAction
 

Functions

static const RecordDecl * findDefinition (StringRef RecordName, ASTContext &Context)
 Finds the definition of a record by name.
 
static SmallVector< unsigned, 4 > getNewFieldsOrder (const RecordDecl *Definition, ArrayRef< std::string > DesiredFieldsOrder)
 Calculates the new order of fields.
 
static void addReplacement (SourceRange Old, SourceRange New, const ASTContext &Context, std::map< std::string, tooling::Replacements > &Replacements)
 Replaces one range of source code by another.
 
static SmallSetVector< FieldDecl *, 1 > findMembersUsedInInitExpr (const CXXCtorInitializer *Initializer, ASTContext &Context)
 Find all member fields used in the given init-list initializer expr that belong to the same record.
 
static bool reorderFieldsInDefinition (const RecordDecl *Definition, ArrayRef< unsigned > NewFieldsOrder, const ASTContext &Context, std::map< std::string, tooling::Replacements > &Replacements)
 Reorders fields in the definition of a struct/class.
 
static void reorderFieldsInConstructor (const CXXConstructorDecl *CtorDecl, ArrayRef< unsigned > NewFieldsOrder, ASTContext &Context, std::map< std::string, tooling::Replacements > &Replacements)
 Reorders initializers in a C++ struct/class constructor.
 
static bool reorderFieldsInInitListExpr (const InitListExpr *InitListEx, ArrayRef< unsigned > NewFieldsOrder, const ASTContext &Context, std::map< std::string, tooling::Replacements > &Replacements)
 Reorders initializers in the brace initialization of an aggregate.
 

Function Documentation

◆ addReplacement()

static void clang::reorder_fields::addReplacement ( SourceRange  Old,
SourceRange  New,
const ASTContext &  Context,
std::map< std::string, tooling::Replacements > &  Replacements 
)
static

Replaces one range of source code by another.

Definition at line 84 of file ReorderFieldsAction.cpp.

Referenced by reorderFieldsInConstructor(), reorderFieldsInDefinition(), and reorderFieldsInInitListExpr().

◆ findDefinition()

static const RecordDecl * clang::reorder_fields::findDefinition ( StringRef  RecordName,
ASTContext &  Context 
)
static

Finds the definition of a record by name.

Returns
nullptr if the name is ambiguous or not found.

Definition at line 36 of file ReorderFieldsAction.cpp.

References Results.

◆ findMembersUsedInInitExpr()

static SmallSetVector< FieldDecl *, 1 > clang::reorder_fields::findMembersUsedInInitExpr ( const CXXCtorInitializer *  Initializer,
ASTContext &  Context 
)
static

Find all member fields used in the given init-list initializer expr that belong to the same record.

Returns
a set of field declarations, empty if none were present

Definition at line 100 of file ReorderFieldsAction.cpp.

References Results.

Referenced by reorderFieldsInConstructor().

◆ getNewFieldsOrder()

static SmallVector< unsigned, 4 > clang::reorder_fields::getNewFieldsOrder ( const RecordDecl *  Definition,
ArrayRef< std::string >  DesiredFieldsOrder 
)
static

Calculates the new order of fields.

Returns
empty vector if the list of fields doesn't match the definition.

Definition at line 57 of file ReorderFieldsAction.cpp.

References Field, and Name.

◆ reorderFieldsInConstructor()

static void clang::reorder_fields::reorderFieldsInConstructor ( const CXXConstructorDecl *  CtorDecl,
ArrayRef< unsigned >  NewFieldsOrder,
ASTContext &  Context,
std::map< std::string, tooling::Replacements > &  Replacements 
)
static

Reorders initializers in a C++ struct/class constructor.

A constructor can have initializers for an arbitrary subset of the class's fields. Thus, we need to ensure that we reorder just the initializers that are present.

Definition at line 160 of file ReorderFieldsAction.cpp.

References addReplacement(), findMembersUsedInInitExpr(), and ID.

◆ reorderFieldsInDefinition()

static bool clang::reorder_fields::reorderFieldsInDefinition ( const RecordDecl *  Definition,
ArrayRef< unsigned >  NewFieldsOrder,
const ASTContext &  Context,
std::map< std::string, tooling::Replacements > &  Replacements 
)
static

Reorders fields in the definition of a struct/class.

At the moment reordering of fields with different accesses (public/protected/private) is not supported.

Returns
true on success.

Definition at line 124 of file ReorderFieldsAction.cpp.

References addReplacement(), and Field.

◆ reorderFieldsInInitListExpr()

static bool clang::reorder_fields::reorderFieldsInInitListExpr ( const InitListExpr *  InitListEx,
ArrayRef< unsigned >  NewFieldsOrder,
const ASTContext &  Context,
std::map< std::string, tooling::Replacements > &  Replacements 
)
static

Reorders initializers in the brace initialization of an aggregate.

At the moment partial initialization is not supported.

Returns
true on success

Definition at line 223 of file ReorderFieldsAction.cpp.

References addReplacement().