1 //===- ClangASTNodesEmitter.h - Generate Clang AST node tables -*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // These tablegen backends emit Clang AST node tables
12 //===----------------------------------------------------------------------===//
14 #ifndef CLANGAST_EMITTER_H
15 #define CLANGAST_EMITTER_H
17 #include "TableGenBackend.h"
25 /// ClangASTNodesEmitter - The top-level class emits .inc files containing
26 /// declarations of Clang statements.
28 class 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
;
33 RecordKeeper
&Records
;
35 const std::string
&BaseSuffix
;
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
]);
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())
52 return R
.getName() + BaseSuffix
;
55 std::pair
<Record
*, Record
*> EmitNode (const ChildMap
&Tree
, raw_ostream
& OS
,
58 explicit ClangASTNodesEmitter(RecordKeeper
&R
, const std::string
&N
,
60 : Records(R
), Root(N
, SMLoc(), R
), BaseSuffix(S
)
63 // run - Output the .inc file contents
64 void run(raw_ostream
&OS
);
67 /// ClangDeclContextEmitter - Emits an addendum to a .inc file to enumerate the
68 /// clang declaration contexts.
70 class ClangDeclContextEmitter
: public TableGenBackend
{
71 RecordKeeper
&Records
;
74 explicit ClangDeclContextEmitter(RecordKeeper
&R
)
78 // run - Output the .inc file contents
79 void run(raw_ostream
&OS
);
82 } // End llvm namespace