Skip to content

Commit 33ebcb1

Browse files
committed
shaders: vendor CppNet preprocessor, drop last submodule
C# port of the Anarres C preprocessor, vendored from: - Upstream: <https://github.com/MonoGame/CppNet> - Commit: `3dc3eb2db05be9d80b7cc5d00d5814cbe8f0ded2` (`master`, "Make all public API internal for MonoGame Pipeline use. (#2)", 2026-01-24) Not copied from upstream (unused by Stride): `CppReader.cs`, `CppTask.cs`, `InputLexerSource.cs`, `TokenSnifferSource.cs`, `CppNet.csproj`, `CppNet.targets`, `Properties/AssemblyInfo.cs`.
1 parent 1d6b62d commit 33ebcb1

31 files changed

Lines changed: 5562 additions & 27 deletions

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

build/submodules/.editorconfig

Lines changed: 0 additions & 13 deletions
This file was deleted.

build/submodules/CppNet8

Lines changed: 0 additions & 1 deletion
This file was deleted.

sources/shaders/.devcontainer/devcontainer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@
1717
},
1818
"features": {
1919
"ghcr.io/devcontainers/features/powershell:1": {}
20-
},
21-
"postStartCommand": "git submodule update --init"
20+
}
2221
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ SDSL is a superset of the HLSL Shading language, bringing advanced and higher le
1919

2020
## Contribute
2121

22-
To contribute to this project, start by cloning this repository and pulling submodules :
22+
To contribute to this project, start by cloning this repository:
2323

2424
```bash
2525
git clone https://github.com/Stride3D/SDSL
2626
cd ./SDSL
27-
git submodule update --init
2827
```
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Anarres C Preprocessor
3+
* Copyright (c) 2007-2008, Shevek
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14+
* or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
18+
#pragma warning disable
19+
20+
using System;
21+
using System.Collections.Generic;
22+
using System.Text;
23+
24+
namespace CppNet {
25+
/**
26+
* A macro argument.
27+
*
28+
* This encapsulates a raw and preprocessed token stream.
29+
*/
30+
internal class Argument : List<Token> {
31+
public const int NO_ARGS = -1;
32+
33+
private List<Token> _expansion;
34+
35+
public Argument() {
36+
this._expansion = null;
37+
}
38+
39+
public void addToken(Token tok) {
40+
Add(tok);
41+
}
42+
43+
internal void expand(Preprocessor p) {
44+
/* Cache expansion. */
45+
if(_expansion == null) {
46+
this._expansion = p.expand(this);
47+
// System.out.println("Expanded arg " + this);
48+
}
49+
}
50+
51+
public Iterator<Token> expansion()
52+
{
53+
return _expansion.iterator();
54+
}
55+
56+
override public String ToString() {
57+
StringBuilder buf = new StringBuilder();
58+
buf.Append("Argument(");
59+
// buf.Append(super.toString());
60+
buf.Append("raw=[ ");
61+
for (int i = 0; i < this.Count; i++)
62+
buf.Append(this[i].getText());
63+
buf.Append(" ];expansion=[ ");
64+
if(_expansion == null)
65+
buf.Append("null");
66+
else
67+
for(int i = 0; i < _expansion.Count; i++)
68+
buf.Append(_expansion[i].getText());
69+
buf.Append(" ])");
70+
return buf.ToString();
71+
}
72+
73+
}
74+
75+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Anarres C Preprocessor
3+
* Copyright (c) 2007-2008, Shevek
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14+
* or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
18+
using System;
19+
20+
namespace CppNet
21+
{
22+
/**
23+
* A handler for preprocessor events, primarily errors and warnings.
24+
*
25+
* If no PreprocessorListener is installed in a Preprocessor, all
26+
* error and warning events will throw an exception. Installing a
27+
* listener allows more intelligent handling of these events.
28+
*/
29+
internal class DefaultPreprocessorListener : PreprocessorListener {
30+
private int errors;
31+
private int warnings;
32+
33+
public DefaultPreprocessorListener() {
34+
clear();
35+
}
36+
37+
public void clear() {
38+
errors = 0;
39+
warnings = 0;
40+
}
41+
42+
public int getErrors() {
43+
return errors;
44+
}
45+
46+
public int getWarnings() {
47+
return warnings;
48+
}
49+
50+
protected void print(String msg) {
51+
System.Console.Error.WriteLine(msg);
52+
}
53+
54+
/**
55+
* Handles a warning.
56+
*
57+
* The behaviour of this method is defined by the
58+
* implementation. It may simply record the error message, or
59+
* it may throw an exception.
60+
*/
61+
public void handleWarning(Source source, int line, int column,
62+
String msg) {
63+
warnings++;
64+
print(source.getName() + ":" + line + ":" + column +
65+
": warning: " + msg);
66+
}
67+
68+
/**
69+
* Handles an error.
70+
*
71+
* The behaviour of this method is defined by the
72+
* implementation. It may simply record the error message, or
73+
* it may throw an exception.
74+
*/
75+
public void handleError(Source source, int line, int column,
76+
String msg) {
77+
errors++;
78+
print(source.getName() + ":" + line + ":" + column +
79+
": error: " + msg);
80+
}
81+
82+
public void handleSourceChange(Source source, String ev) {
83+
}
84+
}
85+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Anarres C Preprocessor
3+
* Copyright (c) 2007-2008, Shevek
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14+
* or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
18+
using System;
19+
20+
namespace CppNet
21+
{
22+
/**
23+
* Features of the Preprocessor, which may be enabled or disabled.
24+
*/
25+
[Flags]
26+
internal enum Feature
27+
{
28+
NONE = 0,
29+
/** Supports ANSI digraphs. */
30+
DIGRAPHS = 1 << 0,
31+
/** Supports ANSI trigraphs. */
32+
TRIGRAPHS = 1 << 1,
33+
/** Outputs linemarker tokens. */
34+
LINEMARKERS = 1 << 2,
35+
/** Reports tokens of type INVALID as errors. */
36+
CSYNTAX = 1 << 3,
37+
/** Preserves comments in the lexed output. */
38+
KEEPCOMMENTS = 1 << 4,
39+
/** Preserves comments in the lexed output, even when inactive. */
40+
KEEPALLCOMMENTS = 1 << 5,
41+
VERBOSE = 1 << 6,
42+
DEBUG = 1 << 7,
43+
44+
/** Supports lexing of objective-C. */
45+
OBJCSYNTAX = 1 << 8,
46+
INCLUDENEXT = 1 << 9
47+
}
48+
49+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Anarres C Preprocessor
3+
* Copyright (c) 2007-2008, Shevek
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14+
* or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
using System;
18+
using System.IO;
19+
20+
namespace CppNet {
21+
22+
/**
23+
* A {@link Source} which lexes a file.
24+
*
25+
* The input is buffered.
26+
*
27+
* @see Source
28+
*/
29+
internal class FileLexerSource : LexerSource {
30+
// private File file;
31+
private String path;
32+
33+
/**
34+
* Creates a new Source for lexing the given File.
35+
*
36+
* Preprocessor directives are honoured within the file.
37+
*/
38+
public FileLexerSource(FileInfo file, String path) : base(new StreamReader(file.OpenRead()), true)
39+
{
40+
41+
// this.file = file;
42+
this.path = path;
43+
}
44+
45+
public FileLexerSource(FileInfo file) :
46+
this(file, file.FullName) {
47+
}
48+
49+
public FileLexerSource(String path) :
50+
this(new FileInfo(path)) {
51+
}
52+
53+
override internal String getPath() {
54+
return path;
55+
}
56+
57+
override internal String getName()
58+
{
59+
return getPath();
60+
}
61+
62+
override public string ToString() {
63+
return "file " + path;
64+
}
65+
}
66+
67+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Anarres C Preprocessor
3+
* Copyright (c) 2007-2008, Shevek
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14+
* or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
18+
using System;
19+
using System.Text;
20+
using System.Collections.Generic;
21+
22+
namespace CppNet {
23+
24+
internal class FixedTokenSource : Source {
25+
private static readonly Token EOF =
26+
new Token(Token.EOF, "<ts-eof>");
27+
28+
private List<Token> tokens;
29+
private int idx;
30+
31+
internal FixedTokenSource(params Token[] tokens) {
32+
this.tokens = new List<Token>(tokens);
33+
this.idx = 0;
34+
}
35+
36+
internal FixedTokenSource(List<Token> tokens) {
37+
this.tokens = tokens;
38+
this.idx = 0;
39+
}
40+
41+
public override Token token() {
42+
if (idx >= tokens.Count)
43+
return EOF;
44+
return tokens[idx++];
45+
}
46+
47+
override public String ToString() {
48+
StringBuilder buf = new StringBuilder();
49+
buf.Append("constant token stream " + tokens);
50+
Source parent = getParent();
51+
if (parent != null)
52+
buf.Append(" in ").Append(parent);
53+
return buf.ToString();
54+
}
55+
}
56+
57+
}

0 commit comments

Comments
 (0)