Skip to content

Commit

Permalink
#78 - added support for builtin type aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
dparnell committed Oct 25, 2024
1 parent a318f21 commit 7fa4f8e
Show file tree
Hide file tree
Showing 17 changed files with 982 additions and 656 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

## Unreleased

- added support for builtin type aliases - #78
- updated to latest IntelliJ platform

## 0.0.32 - 2024-08-01

- remove max release so hopefully it should work for all future versions - @andreypfau
Expand Down
File renamed without changes.
16 changes: 16 additions & 0 deletions examples/ticket_78.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
struct Vertex {
@builtin(position) pos: vec4f;
xxx: mat4x4f
}

@vertex
fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> Vertex {
let x = f32(1 - i32(in_vertex_index)) * 0.5;
let y = f32(i32(in_vertex_index & 1u) * 2 - 1) * 0.5;
return Vertex(vec4(x, y, 0.0, 1.0));
}

@fragment
fn fs_main(in: Vertex) -> @location(0) vec4f {
return vec4(1.0, 0.0, 0.0, 1.0);
}
5 changes: 2 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ pluginVersion = 0.0.32
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild = 222
#pluginUntilBuild = 241.*

# IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties
platformType = IC
platformVersion = 2022.2
platformVersion = 2022.3.3

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
Expand All @@ -23,7 +22,7 @@ platformPlugins = org.intellij.plugins.markdown
javaVersion = 17

# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion = 8.6
gradleVersion = 8.10.2

# Opt-out flag for bundling Kotlin standard library.
# See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details.
Expand Down
1,362 changes: 715 additions & 647 deletions src/main/gen/wgslplugin/language/_WgslLexer.java

Large diffs are not rendered by default.

73 changes: 72 additions & 1 deletion src/main/gen/wgslplugin/language/parser/WgslParser.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/main/gen/wgslplugin/language/parser/WgslParserUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package wgslplugin.language.parser;

import com.intellij.lang.parser.GeneratedParserUtilBase;

public class WgslParserUtil extends GeneratedParserUtilBase {
}
10 changes: 10 additions & 0 deletions src/main/gen/wgslplugin/language/psi/WGSLBuiltinTypeAlias.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/main/gen/wgslplugin/language/psi/WGSLTypeDecl.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions src/main/gen/wgslplugin/language/psi/WGSLTypes.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/main/gen/wgslplugin/language/psi/WGSLVisitor.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/main/java/wgslplugin/language/BuiltInFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -30,7 +31,7 @@ public synchronized WGSLFunctionDecl get(PsiElement element) {
bos.write(buf, 0, L);
L = s.read(buf);
}
builtInFunctionsFile = WGSLElementFactory.createFile(element.getProject(), bos.toString("UTF-8"));
builtInFunctionsFile = WGSLElementFactory.createFile(element.getProject(), bos.toString(StandardCharsets.UTF_8));

allBuiltinFunctions = PsiTreeUtil.collectElements(builtInFunctionsFile, e -> e instanceof WGSLFunctionDecl);
for(PsiElement func : allBuiltinFunctions) {
Expand Down
41 changes: 38 additions & 3 deletions src/main/java/wgslplugin/language/WGSLLexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,48 @@ IDENT = ([a-zA-Z_][0-9a-zA-Z_][0-9a-zA-Z_]*)|([a-zA-Z][0-9a-zA-Z_]*)
<YYINITIAL, BIND_SPEC> "texture_depth_cube_array" { return TEXTURE_DEPTH_CUBE_ARRAY; }
<YYINITIAL, BIND_SPEC> "texture_depth_multisampled_2d" { return TEXTURE_DEPTH_MULTISAMPLED_2D; }

<YYINITIAL> "type" { return TYPE; }
<YYINITIAL> "=" { return EQUAL; }
<TYPE_SPEC> "=" { popState(); return EQUAL; }
<YYINITIAL> "type" { return TYPE; }
<YYINITIAL> "=" { return EQUAL; }
<TYPE_SPEC> "=" { popState(); return EQUAL; }

<YYINITIAL, TYPE_SPEC, BIND_SPEC> "bool" { return BOOL; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "f32" { return FLOAT32; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "i32" { return INT32; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "u32" { return UINT32; }

<YYINITIAL, TYPE_SPEC, BIND_SPEC> "vec2i" { return VEC2I; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "vec3i" { return VEC3I; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "vec4i" { return VEC4I; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "vec2u" { return VEC2U; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "vec3u" { return VEC3U; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "vec4u" { return VEC4U; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "vec2f" { return VEC2F; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "vec3f" { return VEC3F; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "vec4f" { return VEC4F; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "vec2h" { return VEC2H; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "vec3h" { return VEC3H; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "vec4h" { return VEC4H; }

<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat2x2f" { return MAT2X2F; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat2x3f" { return MAT2X3F; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat2x4f" { return MAT2X4F; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat3x2f" { return MAT3X2F; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat3x3f" { return MAT3X3F; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat3x4f" { return MAT3X4F; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat4x2f" { return MAT4X2F; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat4x3f" { return MAT4X3F; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat4x4f" { return MAT4X4F; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat2x2h" { return MAT2X2H; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat2x3h" { return MAT2X3H; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat2x4h" { return MAT2X4H; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat3x2h" { return MAT3X2H; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat3x3h" { return MAT3X3H; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat3x4h" { return MAT3X4H; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat4x2h" { return MAT4X2H; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat4x3h" { return MAT4X3H; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat4x4h" { return MAT4X4H; }


<YYINITIAL, TYPE_SPEC, BIND_SPEC> "vec2" { pushState(TYPE_SPEC); return VEC2; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "vec3" { pushState(TYPE_SPEC); return VEC3; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "vec4" { pushState(TYPE_SPEC); return VEC4; }
Expand All @@ -157,6 +191,7 @@ IDENT = ([a-zA-Z_][0-9a-zA-Z_][0-9a-zA-Z_]*)|([a-zA-Z][0-9a-zA-Z_]*)
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat4x3" { pushState(TYPE_SPEC); return MAT4X3; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "mat4x4" { pushState(TYPE_SPEC); return MAT4X4; }
<YYINITIAL, TYPE_SPEC, BIND_SPEC> "atomic" { pushState(TYPE_SPEC); return ATOMIC; }

<YYINITIAL> "let" { return LET; }
<YYINITIAL> "var" { pushState(TYPE_SPEC); return VAR; }
<YYINITIAL> "const" { pushState(TYPE_SPEC); return CONST; }
Expand Down
Loading

0 comments on commit 7fa4f8e

Please sign in to comment.