Sean Hunt | 44ed2c3 | 2010-05-06 05:24:38 +0000 | [diff] [blame] | 1 | //===- ClangASTNodesEmitter.h - Generate Clang AST node tables -*- C++ -*--===// |
Sean Hunt | 84e2f95 | 2010-05-05 04:13:08 +0000 | [diff] [blame] | 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 | // |
Sean Hunt | 44ed2c3 | 2010-05-06 05:24:38 +0000 | [diff] [blame] | 10 | // These tablegen backends emit Clang AST node tables |
Sean Hunt | 84e2f95 | 2010-05-05 04:13:08 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef CLANGAST_EMITTER_H |
| 15 | #define CLANGAST_EMITTER_H |
| 16 | |
| 17 | #include "TableGenBackend.h" |
Sean Hunt | c10a62b | 2010-05-30 07:21:42 +0000 | [diff] [blame] | 18 | #include "Record.h" |
| 19 | #include <string> |
| 20 | #include <cctype> |
| 21 | #include <map> |
Sean Hunt | 84e2f95 | 2010-05-05 04:13:08 +0000 | [diff] [blame] | 22 | |
| 23 | namespace llvm { |
| 24 | |
Sean Hunt | 891f273 | 2010-06-01 23:29:39 +0000 | [diff] [blame] | 25 | /// ClangASTNodesEmitter - The top-level class emits .inc files containing |
Sean Hunt | 84e2f95 | 2010-05-05 04:13:08 +0000 | [diff] [blame] | 26 | /// declarations of Clang statements. |
| 27 | /// |
Sean Hunt | c10a62b | 2010-05-30 07:21:42 +0000 | [diff] [blame] | 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; |
Sean Hunt | 84e2f95 | 2010-05-05 04:13:08 +0000 | [diff] [blame] | 32 | |
Sean Hunt | c10a62b | 2010-05-30 07:21:42 +0000 | [diff] [blame] | 33 | 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); |
| 57 | public: |
| 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 | /// |
| 70 | class ClangDeclContextEmitter : public TableGenBackend { |
| 71 | RecordKeeper &Records; |
| 72 | |
| 73 | public: |
| 74 | explicit ClangDeclContextEmitter(RecordKeeper &R) |
| 75 | : Records(R) |
| 76 | {} |
| 77 | |
| 78 | // run - Output the .inc file contents |
Sean Hunt | 84e2f95 | 2010-05-05 04:13:08 +0000 | [diff] [blame] | 79 | void run(raw_ostream &OS); |
| 80 | }; |
| 81 | |
| 82 | } // End llvm namespace |
| 83 | |
| 84 | #endif |