blob: fbdd2a7b2fbeddf421f124bc135e4da3aea364b4 [file] [log] [blame]
Sean Hunt16171442010-06-16 23:45:50 +00001//===- 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
11//
12//===----------------------------------------------------------------------===//
13
14#include "ClangAttrEmitter.h"
15#include "Record.h"
16#include <algorithm>
17
18using namespace llvm;
19
20void 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";
24
25 std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr");
26
27 for (std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end();
28 i != e; ++i) {
29 Record &R = **i;
30
31 if (R.getValueAsBit("DoNotEmit"))
32 continue;
33
34 OS << "class " << R.getName() << "Attr : public Attr {\n";
35
36 std::vector<Record*> Args = R.getValueAsListOfDefs("Args");
Sean Hunt16171442010-06-16 23:45:50 +000037
38 // FIXME: Handle arguments
39 assert(Args.empty() && "Can't yet handle arguments");
40
41 OS << "\n public:\n";
42 OS << " " << R.getName() << "Attr(";
43
44 // Arguments go here
45
46 OS << ")\n";
47 OS << " : Attr(attr::" << R.getName() << ")";
48
49 // Arguments go here
50
51 OS << " {}\n\n";
52
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";
59 }
60
61 OS << "#endif\n";
62}
63
64void ClangAttrListEmitter::run(raw_ostream &OS) {
65 OS << "// This file is generated by TableGen. Do not edit.\n\n";
66
67 OS << "#ifndef LAST_ATTR\n";
68 OS << "#define LAST_ATTR(NAME) ATTR(NAME)\n";
69 OS << "#endif\n\n";
70
71 std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr");
72 std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end();
73
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";
78
79 OS << "LAST_ATTR(" << (*i)->getName() << ")\n\n";
80 }
81
82 OS << "#undef LAST_ATTR\n";
83 OS << "#undef ATTR\n";
84}