Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions source/slang/slang-ast-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#pragma once

#include "slang-ast-base.h"

//
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't an empty line sufficient? The // line shouldn't be needed?

Copy link
Copy Markdown
Contributor Author

@samestep samestep Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@csyonghe no, I tried that when writing this PR and it didn't work; e.g. if you write this in source/slang/slang-ast-modifier.h:

#include "slang-ast-base.h"
#include "slang-ir-insts-enum.h"

#include "slang-ast-modifier.h.fiddle"

then clang-format rewrites it as this:

#include "slang-ast-base.h"
#include "slang-ast-modifier.h.fiddle"
#include "slang-ir-insts-enum.h"

which is incorrect.

This is because we use Regroup for the IncludeBlocks setting:

slang/.clang-format

Lines 8 to 10 in 2d23a96

# Preprocessor
AlignEscapedNewlines: Left
IncludeBlocks: Regroup

Your suggestion would work if we were using IncludeBlocks: Preserve, but the // lines here make that unnecessary.

#include "slang-ast-expr.h.fiddle"

FIDDLE()
Expand Down
4 changes: 3 additions & 1 deletion source/slang/slang-ast-modifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#pragma once

#include "slang-ast-base.h"
#include "slang-ast-modifier.h.fiddle"
#include "slang-ir-insts-enum.h"

//
#include "slang-ast-modifier.h.fiddle"

FIDDLE()
namespace Slang
{
Expand Down
2 changes: 2 additions & 0 deletions source/slang/slang-ast-stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#pragma once

#include "slang-ast-base.h"

//
#include "slang-ast-stmt.h.fiddle"

FIDDLE()
Expand Down
2 changes: 2 additions & 0 deletions source/slang/slang-ast-val.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "slang-ast-base.h"
#include "slang-ast-decl.h"

//
#include "slang-ast-val.h.fiddle"

FIDDLE()
Expand Down
16 changes: 12 additions & 4 deletions tools/slang-fiddle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Invoking Fiddle

Fiddle gets invoked from the command line with a command line like:

```
```sh
slang-fiddle -i source/ -o generated/ a.cpp b.h c.h d.cpp ...
```

Expand Down Expand Up @@ -51,7 +51,7 @@ During the scraping step, Fiddle will run the Slang lexer on each of the input f

Putting `FIDDLE()` in front of an ordinary C++ `class`, `struct`, or `namespace` declaration tells Fiddle that it should include that C++ construct in the model of the program that it scrapes. For example, given this input:

```
```cpp
FIDDLE()
namespace MyProgram
{
Expand All @@ -68,7 +68,7 @@ Fiddle will include the `MyProgram` namespace and the `MyProgram::A` type in its

A programmer can place Fiddle-specific modifiers inside the `FIDDLE()` invocation before a type, to apply those modifiers to the model of that type:

```
```cpp
FIDDLE(abstract)
class Thing { /* ... */ };

Expand All @@ -78,7 +78,7 @@ class ConcreteThing : public Thing { /* ... */ }

One important constraint is that any `struct` or `class` type marked with `FIDDLE()` *must* have an invocation of the form `FIDDLE(...)` (that is, `FIDDLE` applied to an actual ellipsis `...`) as the first item after the opening curly brace for its body:

```
```cpp
FIDDLE()
struct A
{
Expand All @@ -98,6 +98,14 @@ Note again that Fiddle will *ignore* any fields not marked with `FIDDLE()`, so b
In order for Fiddle to provide the macros that each `FIDDLE()` invocation expands into, any input file that includes invocations of `FIDDLE()` *must* also `#include` the corresponding generated file.
For example, the input file `a.cpp` should `#include "a.cpp.fiddle"`.
The `#include` of the generated output file should come *after* any other `#include`s, to make sure that any `.h` files that also use `FIDDLE()` don't cause confusion.
Because `clang-format` automatically reorders `#include`s, you must separate this one from the others by preceding it with a blank line followed by an empty comment line:

```cpp
#include "something-else.h"

//
#include "a.cpp.fiddle"
```

Text Templates
--------------
Expand Down
Loading