blob: abf9c9a0f164968b9d51e346e6f1ac020ac4dba1 [file] [log] [blame]
Sean Hunt44ed2c32010-05-06 05:24:38 +00001//===- ClangASTNodesEmitter.h - Generate Clang AST node tables -*- C++ -*--===//
Sean Hunt84e2f952010-05-05 04:13:08 +00002//
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//
Sean Hunt44ed2c32010-05-06 05:24:38 +000010// These tablegen backends emit Clang AST node tables
Sean Hunt84e2f952010-05-05 04:13:08 +000011//
12//===----------------------------------------------------------------------===//
13
14#ifndef CLANGAST_EMITTER_H
15#define CLANGAST_EMITTER_H
16
17#include "TableGenBackend.h"
Sean Huntc10a62b2010-05-30 07:21:42 +000018#include "Record.h"
19#include <string>
20#include <cctype>
21#include <map>
Sean Hunt84e2f952010-05-05 04:13:08 +000022
23namespace llvm {
24
Sean Hunt891f2732010-06-01 23:29:39 +000025/// ClangASTNodesEmitter - The top-level class emits .inc files containing
Sean Hunt84e2f952010-05-05 04:13:08 +000026/// declarations of Clang statements.
27///
Sean Huntc10a62b2010-05-30 07:21:42 +000028class ClangASTNodesEmitter : public TableGenBackend {
29 // A map from a node to each of its derived nodes.
30 typedef std::multimap<Record*, Record*> ChildMap;
31 typedef ChildMap::const_iterator ChildIterator;
Sean Hunt84e2f952010-05-05 04:13:08 +000032
Sean Huntc10a62b2010-05-30 07:21:42 +000033 RecordKeeper &Records;
34 Record Root;
35 const std::string &BaseSuffix;
36
37 // Create a macro-ized version of a name
38 static std::string macroName(std::string S) {
39 for (unsigned i = 0; i < S.size(); ++i)
40 S[i] = std::toupper(S[i]);
41
42 return S;
43 }
44
45 // Return the name to be printed in the base field. Normally this is
46 // the record's name plus the base suffix, but if it is the root node and
47 // the suffix is non-empty, it's just the suffix.
48 std::string baseName(Record &R) {
49 if (&R == &Root && !BaseSuffix.empty())
50 return BaseSuffix;
51
52 return R.getName() + BaseSuffix;
53 }
54
55 std::pair<Record *, Record *> EmitNode (const ChildMap &Tree, raw_ostream& OS,
56 Record *Base);
57public:
58 explicit ClangASTNodesEmitter(RecordKeeper &R, const std::string &N,
59 const std::string &S)
60 : Records(R), Root(N, SMLoc()), BaseSuffix(S)
61 {}
62
63 // run - Output the .inc file contents
64 void run(raw_ostream &OS);
65};
66
67/// ClangDeclContextEmitter - Emits an addendum to a .inc file to enumerate the
68/// clang declaration contexts.
69///
70class ClangDeclContextEmitter : public TableGenBackend {
71 RecordKeeper &Records;
72
73public:
74 explicit ClangDeclContextEmitter(RecordKeeper &R)
75 : Records(R)
76 {}
77
78 // run - Output the .inc file contents
Sean Hunt84e2f952010-05-05 04:13:08 +000079 void run(raw_ostream &OS);
80};
81
82} // End llvm namespace
83
84#endif