Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ getNewFieldsOrder(const RecordDecl *Definition,
static void
addReplacement(SourceRange Old, SourceRange New, const ASTContext &Context,
std::map<std::string, tooling::Replacements> &Replacements) {
if (Old.getBegin().isMacroID())
Old = Context.getSourceManager().getExpansionRange(Old).getAsRange();
if (New.getBegin().isMacroID())
New = Context.getSourceManager().getExpansionRange(New).getAsRange();
StringRef NewText =
Lexer::getSourceText(CharSourceRange::getTokenRange(New),
Context.getSourceManager(), Context.getLangOpts());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: clang-reorder-fields -record-name ::bar::Foo -fields-order z,y,x %s -- | FileCheck %s

namespace bar {

#define INT_DECL(NAME) int NAME // CHECK: {{^#define INT_DECL\(NAME\) int NAME}}
#define MACRO_DECL int x; // CHECK-NEXT: {{^#define MACRO_DECL int x;}}

struct Foo {
MACRO_DECL // CHECK: {{^ INT_DECL\(z\);}}
int y; // CHECK-NEXT: {{^ int y;}}
INT_DECL(z); // CHECK-NEXT: {{^ MACRO_DECL}}
};

#define FOO 0 // CHECK: {{^#define FOO 0}}
#define BAR 1 // CHECK-NEXT: {{^#define BAR 1}}
#define BAZ 2 // CHECK-NEXT: {{^#define BAZ 2}}

struct Foo foo = {
FOO, // CHECK: {{^ BAZ,}}
BAR, // CHECK-NEXT: {{^ BAR,}}
BAZ, // CHECK-NEXT: {{^ FOO,}}
};

} // end namespace bar