summaryrefslogtreecommitdiff
path: root/utils/TableGen/ClangASTNodesEmitter.h
diff options
context:
space:
mode:
authorSean Hunt <rideau3@gmail.com>2010-05-30 07:21:42 +0000
committerSean Hunt <rideau3@gmail.com>2010-05-30 07:21:42 +0000
commitc10a62b0d53a7cb39b2ccb12c2dd9748ccd12f43 (patch)
tree286be808e7f1b060e2bfcc38f6fed13df07ac2f7 /utils/TableGen/ClangASTNodesEmitter.h
parent4ed81ecbcd139fe13985a1b962f6cd522b90b79e (diff)
downloadllvm-c10a62b0d53a7cb39b2ccb12c2dd9748ccd12f43.tar.gz
llvm-c10a62b0d53a7cb39b2ccb12c2dd9748ccd12f43.tar.bz2
llvm-c10a62b0d53a7cb39b2ccb12c2dd9748ccd12f43.tar.xz
Allow for creation of clang DeclNodes tables.
The StmtNodes generator has been generalized to allow for the creation of DeclNodes tables as well, and another emitter was added for DeclContexts. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@105164 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/ClangASTNodesEmitter.h')
-rw-r--r--utils/TableGen/ClangASTNodesEmitter.h58
1 files changed, 53 insertions, 5 deletions
diff --git a/utils/TableGen/ClangASTNodesEmitter.h b/utils/TableGen/ClangASTNodesEmitter.h
index c4ce9fa820..55d9a1c58b 100644
--- a/utils/TableGen/ClangASTNodesEmitter.h
+++ b/utils/TableGen/ClangASTNodesEmitter.h
@@ -15,19 +15,67 @@
#define CLANGAST_EMITTER_H
#include "TableGenBackend.h"
+#include "Record.h"
+#include <string>
+#include <cctype>
+#include <map>
namespace llvm {
-/// ClangStmtNodesEmitter - The top-level class emits .def files containing
+/// ClangStmtNodesEmitter - The top-level class emits .inc files containing
/// declarations of Clang statements.
///
-class ClangStmtNodesEmitter : public TableGenBackend {
+class ClangASTNodesEmitter : public TableGenBackend {
+ // A map from a node to each of its derived nodes.
+ typedef std::multimap<Record*, Record*> ChildMap;
+ typedef ChildMap::const_iterator ChildIterator;
+
RecordKeeper &Records;
+ Record Root;
+ const std::string &BaseSuffix;
+
+ // Create a macro-ized version of a name
+ static std::string macroName(std::string S) {
+ for (unsigned i = 0; i < S.size(); ++i)
+ S[i] = std::toupper(S[i]);
+
+ return S;
+ }
+
+ // Return the name to be printed in the base field. Normally this is
+ // the record's name plus the base suffix, but if it is the root node and
+ // the suffix is non-empty, it's just the suffix.
+ std::string baseName(Record &R) {
+ if (&R == &Root && !BaseSuffix.empty())
+ return BaseSuffix;
+
+ return R.getName() + BaseSuffix;
+ }
+
+ std::pair<Record *, Record *> EmitNode (const ChildMap &Tree, raw_ostream& OS,
+ Record *Base);
+public:
+ explicit ClangASTNodesEmitter(RecordKeeper &R, const std::string &N,
+ const std::string &S)
+ : Records(R), Root(N, SMLoc()), BaseSuffix(S)
+ {}
+
+ // run - Output the .inc file contents
+ void run(raw_ostream &OS);
+};
+
+/// ClangDeclContextEmitter - Emits an addendum to a .inc file to enumerate the
+/// clang declaration contexts.
+///
+class ClangDeclContextEmitter : public TableGenBackend {
+ RecordKeeper &Records;
+
public:
- explicit ClangStmtNodesEmitter(RecordKeeper &R)
- : Records(R) {}
+ explicit ClangDeclContextEmitter(RecordKeeper &R)
+ : Records(R)
+ {}
- // run - Output the .def file contents
+ // run - Output the .inc file contents
void run(raw_ostream &OS);
};