blob: 95bc1a5877dfa732ecd0c77ef3dce55bd5818524 [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");
37 std::vector<Record*>::iterator ai, ae = Args.end();
38
39 // FIXME: Handle arguments
40 assert(Args.empty() && "Can't yet handle arguments");
41
42 OS << "\n public:\n";
43 OS << " " << R.getName() << "Attr(";
44
45 // Arguments go here
46
47 OS << ")\n";
48 OS << " : Attr(attr::" << R.getName() << ")";
49
50 // Arguments go here
51
52 OS << " {}\n\n";
53
54 OS << " virtual Attr *clone (ASTContext &C) const;\n";
55 OS << " static bool classof(const Attr *A) { return A->getKind() == "
56 << "attr::" << R.getName() << "; }\n";
57 OS << " static bool classof(const " << R.getName()
58 << "Attr *) { return true; }\n";
59 OS << "};\n\n";
60 }
61
62 OS << "#endif\n";
63}
64
65void ClangAttrListEmitter::run(raw_ostream &OS) {
66 OS << "// This file is generated by TableGen. Do not edit.\n\n";
67
68 OS << "#ifndef LAST_ATTR\n";
69 OS << "#define LAST_ATTR(NAME) ATTR(NAME)\n";
70 OS << "#endif\n\n";
71
72 std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr");
73 std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end();
74
75 if (i != e) {
76 // Move the end iterator back to emit the last attribute.
77 for(--e; i != e; ++i)
78 OS << "ATTR(" << (*i)->getName() << ")\n";
79
80 OS << "LAST_ATTR(" << (*i)->getName() << ")\n\n";
81 }
82
83 OS << "#undef LAST_ATTR\n";
84 OS << "#undef ATTR\n";
85}