//===- ClangSyntaxEmitter.cpp - Generate clang Syntax Tree nodes ----------===// // // The LLVM Compiler Infrastructure // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // These backends consume the definitions of Syntax Tree nodes. // See clang/include/clang/Tooling/Syntax/{Syntax,Nodes}.td // // The -gen-clang-syntax-node-list backend produces a .inc with macro calls // NODE(Kind, BaseKind) // ABSTRACT_NODE(Type, Base, FirstKind, LastKind) // similar to those for AST nodes such as AST/DeclNodes.inc. // // The -gen-clang-syntax-node-classes backend produces definitions for the // syntax::Node subclasses (except those marked as External). // // In future, another backend will encode the structure of the various node // types in tables so their invariants can be checked and enforced. // //===----------------------------------------------------------------------===// #include "TableGenBackends.h" #include <deque> #include "llvm/ADT/StringExtras.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TableGen/Record.h" #include "llvm/TableGen/TableGenBackend.h" usingnamespacellvm; namespace { // The class hierarchy of Node types. // We assemble this in order to be able to define the NodeKind enum in a // stable and useful way, where abstract Node subclasses correspond to ranges. class Hierarchy { … }; const Hierarchy::NodeType &firstConcrete(const Hierarchy::NodeType &N) { … } const Hierarchy::NodeType &lastConcrete(const Hierarchy::NodeType &N) { … } struct SyntaxConstraint { … }; } // namespace void clang::EmitClangSyntaxNodeList(const RecordKeeper &Records, raw_ostream &OS) { … } // Format a documentation string as a C++ comment. // Trims leading whitespace handling since comments come from a TableGen file: // documentation = [{ // This is a widget. Example: // widget.explode() // }]; // and should be formatted as: // /// This is a widget. Example: // /// widget.explode() // Leading and trailing whitespace lines are stripped. // The indentation of the first line is stripped from all lines. static void printDoc(StringRef Doc, raw_ostream &OS) { … } void clang::EmitClangSyntaxNodeClasses(const RecordKeeper &Records, raw_ostream &OS) { … }