r201246 - Attributes: Emit enumerators in td file declaration order
Reid Kleckner
reid at kleckner.net
Wed Feb 12 10:22:18 PST 2014
Author: rnk
Date: Wed Feb 12 12:22:18 2014
New Revision: 201246
URL: http://llvm.org/viewvc/llvm-project?rev=201246&view=rev
Log:
Attributes: Emit enumerators in td file declaration order
Modified:
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=201246&r1=201245&r2=201246&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Wed Feb 12 12:22:18 2014
@@ -606,6 +606,22 @@ namespace {
}
};
+ // Unique the enums, but maintain the original declaration ordering.
+ std::vector<std::string> uniqueEnumsInOrder(std::vector<std::string> enums) {
+ std::vector<std::string> uniques;
+ std::set<std::string> unique_set(enums.begin(), enums.end());
+ for (std::vector<std::string>::const_iterator i = enums.begin(),
+ e = enums.end();
+ i != e; ++i) {
+ std::set<std::string>::iterator set_i = unique_set.find(*i);
+ if (set_i != unique_set.end()) {
+ uniques.push_back(*i);
+ unique_set.erase(set_i);
+ }
+ }
+ return uniques;
+ }
+
class EnumArgument : public Argument {
std::string type;
std::vector<std::string> values, enums, uniques;
@@ -614,11 +630,8 @@ namespace {
: Argument(Arg, Attr), type(Arg.getValueAsString("Type")),
values(Arg.getValueAsListOfStrings("Values")),
enums(Arg.getValueAsListOfStrings("Enums")),
- uniques(enums)
+ uniques(uniqueEnumsInOrder(enums))
{
- // Calculate the various enum values
- std::sort(uniques.begin(), uniques.end());
- uniques.erase(std::unique(uniques.begin(), uniques.end()), uniques.end());
// FIXME: Emit a proper error
assert(!uniques.empty());
}
@@ -711,12 +724,8 @@ namespace {
type(Arg.getValueAsString("Type")),
values(Arg.getValueAsListOfStrings("Values")),
enums(Arg.getValueAsListOfStrings("Enums")),
- uniques(enums)
+ uniques(uniqueEnumsInOrder(enums))
{
- // Calculate the various enum values
- std::sort(uniques.begin(), uniques.end());
- uniques.erase(std::unique(uniques.begin(), uniques.end()), uniques.end());
-
QualifiedTypeName = getAttrName().str() + "Attr::" + type;
// FIXME: Emit a proper error
More information about the cfe-commits
mailing list