Home | History | Annotate | Download | only in TableGen
      1 //===- ClangASTNodesEmitter.h - Generate Clang AST node tables -*- 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 AST node tables
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef CLANGAST_EMITTER_H
     15 #define CLANGAST_EMITTER_H
     16 
     17 #include "llvm/TableGen/TableGenBackend.h"
     18 #include "llvm/TableGen/Record.h"
     19 #include <string>
     20 #include <cctype>
     21 #include <map>
     22 
     23 namespace llvm {
     24 
     25 /// ClangASTNodesEmitter - The top-level class emits .inc files containing
     26 ///  declarations of Clang statements.
     27 ///
     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;
     32 
     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(), R), 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
     79   void run(raw_ostream &OS);
     80 };
     81 
     82 } // End llvm namespace
     83 
     84 #endif
     85