clang-tools  14.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. More...
 
static SmallVector< unsigned, 4 > getNewFieldsOrder (const RecordDecl *Definition, ArrayRef< std::string > DesiredFieldsOrder)
 Calculates the new order of fields. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 

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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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 224 of file ReorderFieldsAction.cpp.