diff options
| author | Michael Han <fragmentshaders@gmail.com> | 2013-02-01 01:19:17 +0000 |
|---|---|---|
| committer | Michael Han <fragmentshaders@gmail.com> | 2013-02-01 01:19:17 +0000 |
| commit | af02bbe84f653125d50bfded5f854baf48c307f9 (patch) | |
| tree | b39061a7071ee992e3ce68b7f0ce9945833d2519 /clang/utils | |
| parent | c79cdff1959fb3e54ad3d24c18ecfb9f5b4b1c76 (diff) | |
| download | bcm5719-llvm-af02bbe84f653125d50bfded5f854baf48c307f9.tar.gz bcm5719-llvm-af02bbe84f653125d50bfded5f854baf48c307f9.zip | |
[Sema][Attr]Fix alignment attribute printing.
Remove "IsMSDeclspec" argument from Align attribute since the arguments in Attr.td should
only model those appear in source code. Introduce attribute Accessor, and teach TableGen
to generate syntax kind accessors for Align attribute, and use those accessors to decide
if an alignment attribute is a declspec attribute.
llvm-svn: 174133
Diffstat (limited to 'clang/utils')
| -rw-r--r-- | clang/utils/TableGen/ClangAttrEmitter.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index 65a009c214e..544ec29faba 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -829,6 +829,51 @@ static void writePrettyPrintFunction(Record &R, std::vector<Argument*> &Args, OS << "}\n\n"; } +/// \brief Return the index of a spelling in a spelling list. +static unsigned getSpellingListIndex(const std::vector<Record*> &SpellingList, + const Record &Spelling) { + assert(SpellingList.size() && "Spelling list is empty!"); + + for (unsigned Index = 0; Index < SpellingList.size(); ++Index) { + Record *S = SpellingList[Index]; + if (S->getValueAsString("Variety") != Spelling.getValueAsString("Variety")) + continue; + if (S->getValueAsString("Variety") == "CXX11" && + S->getValueAsString("Namespace") != + Spelling.getValueAsString("Namespace")) + continue; + if (S->getValueAsString("Name") != Spelling.getValueAsString("Name")) + continue; + + return Index; + } + + llvm_unreachable("Unknown spelling!"); +} + +static void writeAttrAccessorDefinition(Record &R, raw_ostream &OS) { + std::vector<Record*> Accessors = R.getValueAsListOfDefs("Accessors"); + for (std::vector<Record*>::const_iterator I = Accessors.begin(), + E = Accessors.end(); I != E; ++I) { + Record *Accessor = *I; + std::string Name = Accessor->getValueAsString("Name"); + std::vector<Record*> Spellings = Accessor->getValueAsListOfDefs( + "Spellings"); + std::vector<Record*> SpellingList = R.getValueAsListOfDefs("Spellings"); + assert(SpellingList.size() && + "Attribute with empty spelling list can't have accessors!"); + + OS << " bool " << Name << "() const { return SpellingListIndex == "; + for (unsigned Index = 0; Index < Spellings.size(); ++Index) { + OS << getSpellingListIndex(SpellingList, *Spellings[Index]); + if (Index != Spellings.size() -1) + OS << " ||\n SpellingListIndex == "; + else + OS << "; }\n"; + } + } +} + namespace clang { // Emits the class definitions for attributes. @@ -903,6 +948,8 @@ void EmitClangAttrClass(RecordKeeper &Records, raw_ostream &OS) { OS << " virtual void printPretty(raw_ostream &OS,\n" << " const PrintingPolicy &Policy) const;\n"; + writeAttrAccessorDefinition(R, OS); + for (ai = Args.begin(); ai != ae; ++ai) { (*ai)->writeAccessors(OS); OS << "\n\n"; |

