Do more to modernize MergeFunctions. Refactor in response to Chris' code review.
[llvm.git] / utils / TableGen / ClangAttrEmitter.cpp
blobfbdd2a7b2fbeddf421f124bc135e4da3aea364b4
1 //===- ClangAttrEmitter.cpp - Generate Clang attribute handling =-*- C++ -*--=//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // These tablegen backends emit Clang attribute processing code
12 //===----------------------------------------------------------------------===//
14 #include "ClangAttrEmitter.h"
15 #include "Record.h"
16 #include <algorithm>
18 using namespace llvm;
20 void ClangAttrClassEmitter::run(raw_ostream &OS) {
21 OS << "// This file is generated by TableGen. Do not edit.\n\n";
22 OS << "#ifndef LLVM_CLANG_ATTR_CLASSES_INC\n";
23 OS << "#define LLVM_CLANG_ATTR_CLASSES_INC\n\n";
25 std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr");
27 for (std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end();
28 i != e; ++i) {
29 Record &R = **i;
31 if (R.getValueAsBit("DoNotEmit"))
32 continue;
34 OS << "class " << R.getName() << "Attr : public Attr {\n";
36 std::vector<Record*> Args = R.getValueAsListOfDefs("Args");
38 // FIXME: Handle arguments
39 assert(Args.empty() && "Can't yet handle arguments");
41 OS << "\n public:\n";
42 OS << " " << R.getName() << "Attr(";
44 // Arguments go here
46 OS << ")\n";
47 OS << " : Attr(attr::" << R.getName() << ")";
49 // Arguments go here
51 OS << " {}\n\n";
53 OS << " virtual Attr *clone (ASTContext &C) const;\n";
54 OS << " static bool classof(const Attr *A) { return A->getKind() == "
55 << "attr::" << R.getName() << "; }\n";
56 OS << " static bool classof(const " << R.getName()
57 << "Attr *) { return true; }\n";
58 OS << "};\n\n";
61 OS << "#endif\n";
64 void ClangAttrListEmitter::run(raw_ostream &OS) {
65 OS << "// This file is generated by TableGen. Do not edit.\n\n";
67 OS << "#ifndef LAST_ATTR\n";
68 OS << "#define LAST_ATTR(NAME) ATTR(NAME)\n";
69 OS << "#endif\n\n";
71 std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr");
72 std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end();
74 if (i != e) {
75 // Move the end iterator back to emit the last attribute.
76 for(--e; i != e; ++i)
77 OS << "ATTR(" << (*i)->getName() << ")\n";
79 OS << "LAST_ATTR(" << (*i)->getName() << ")\n\n";
82 OS << "#undef LAST_ATTR\n";
83 OS << "#undef ATTR\n";