[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

Paul Kirth via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 21 10:29:52 PST 2024


================
@@ -0,0 +1,731 @@
+//===-- Mustache.cpp ------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include <sstream>
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+namespace {
----------------
ilovepi wrote:

I wouldn't expect the anonymous namepace to be used inside `llvm::mustache`. Since you're just using that for Token and ASTNode, I don't think there's an issue w/ those living inside `llvm::mustache`. 

The free functions probably don't need to be in the `mustache` namespace, but there isn't a huge reason why they can't be either. Lets just move those functions into one area, and mark them as `static`. That way its easy to see that they're only used locally w/in the TU, and you don't have to worry so much about opening/closing the namespaces.

If you want an example, https://github.com/llvm/llvm-project/blob/0611a668d1389c8573e83eeafa6d5f6172c4cbc2/llvm/lib/IR/ProfDataUtils.cpp#L68 is the kind of thing I was thinking of. The anonymous namespace is at the top of the file, and holds a bunch of free functions.  the function itself is `static`, because its only used w/in ProfDataUtils.cpp (the function above should actually be `static` too).

https://github.com/llvm/llvm-project/pull/105893


More information about the cfe-commits mailing list