[PATCH] D125667: [pseudo] A basic implementation of compiling cxx grammar at build time.

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 23 08:51:35 PDT 2022


sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.


================
Comment at: clang-tools-extra/pseudo/lib/cxx/CXX.cpp:17
+static const char *CxxBNF =
+#include "CXXBNF.inc"
+    ;
----------------
this is worth a try, but I think (some versions of?) MSVC don't like long string literals.

Stackoverflow says 2k per "chunk" ("one" "two" "three") and 64k total.
Integer arrays can be larger...

So let's start with simple readable options, and make them progressively uglier if we hit limits.


================
Comment at: clang-tools-extra/pseudo/lib/cxx/CXX.cpp:22
+  static std::vector<std::string> Diags;
+  static std::unique_ptr<Grammar> G = Grammar::parseBNF(CxxBNF, Diags);
+  assert(Diags.empty());
----------------
static Grammar &G = *Grammar::parseBNF(...).release();
to avoid destruction


================
Comment at: clang-tools-extra/pseudo/lib/cxx/CXX.cpp:28
+const LRTable &getLRTable() {
+  static LRTable Table = LRTable::buildSLR(getGrammar());
+  return Table;
----------------
similarly &Table = *new LRTable(buildSLR(...));


================
Comment at: clang-tools-extra/pseudo/lib/grammar/CMakeLists.txt:3
+
+add_clang_library(clangPseudoGrammar
+  Grammar.cpp
----------------
a comment why we want minimal deps here?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125667/new/

https://reviews.llvm.org/D125667



More information about the cfe-commits mailing list