diff options
author | Michael Kruse <llvm@meinersbur.de> | 2018-09-24 06:31:37 +0000 |
---|---|---|
committer | Michael Kruse <llvm@meinersbur.de> | 2018-09-24 06:31:37 +0000 |
commit | 4c99f5fe2b5ca6a880e6a6d3858893f88b6eefe5 (patch) | |
tree | 7e11d6ed0ae11140582633fd440be72925c60050 /clang/lib/AST/DeclBase.cpp | |
parent | 2b8107614c1c9c84007c2882875bb8366f120491 (diff) | |
download | bcm5719-llvm-4c99f5fe2b5ca6a880e6a6d3858893f88b6eefe5.tar.gz bcm5719-llvm-4c99f5fe2b5ca6a880e6a6d3858893f88b6eefe5.zip |
Add inherited attributes before parsed attributes.
Currently, attributes from previous declarations ('inherited attributes')
are added to the end of a declaration's list of attributes. Before
r338800, the attribute list was in reverse. r338800 changed the order
of non-inherited (parsed from the current declaration) attributes, but
inherited attributes are still appended to the end of the list.
This patch appends inherited attributes after other inherited
attributes, but before any non-inherited attribute. This is to make the
order of attributes in the AST correspond to the order in the source
code.
Differential Revision: https://reviews.llvm.org/D50214
llvm-svn: 342861
Diffstat (limited to 'clang/lib/AST/DeclBase.cpp')
-rw-r--r-- | clang/lib/AST/DeclBase.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 6bb2034a9ea..b706e504a3a 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -836,6 +836,29 @@ void Decl::dropAttrs() { getASTContext().eraseDeclAttrs(this); } +void Decl::addAttr(Attr *A) { + if (!hasAttrs()) { + setAttrs(AttrVec(1, A)); + return; + } + + AttrVec &Attrs = getAttrs(); + if (!A->isInherited()) { + Attrs.push_back(A); + return; + } + + // Attribute inheritance is processed after attribute parsing. To keep the + // order as in the source code, add inherited attributes before non-inherited + // ones. + auto I = Attrs.begin(), E = Attrs.end(); + for (; I != E; ++I) { + if (!(*I)->isInherited()) + break; + } + Attrs.insert(I, A); +} + const AttrVec &Decl::getAttrs() const { assert(HasAttrs && "No attrs to get!"); return getASTContext().getDeclAttrs(this); |