summaryrefslogtreecommitdiff
path: root/clang/utils/TableGen/ClangASTNodesEmitter.h
blob: edd9316544eab806ea2b168337f080d2d8a1f79d (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//===- ClangASTNodesEmitter.h - Generate Clang AST node tables -*- C++ -*--===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// These tablegen backends emit Clang AST node tables
//
//===----------------------------------------------------------------------===//

#ifndef CLANGAST_EMITTER_H
#define CLANGAST_EMITTER_H

#include "llvm/TableGen/TableGenBackend.h"
#include "llvm/TableGen/Record.h"
#include <string>
#include <cctype>
#include <map>

namespace llvm {

/// ClangASTNodesEmitter - The top-level class emits .inc files containing
///  declarations of Clang statements.
///
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(), R), 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 ClangDeclContextEmitter(RecordKeeper &R)
    : Records(R)
  {}

  // run - Output the .inc file contents
  void run(raw_ostream &OS);
};

} // End llvm namespace

#endif