Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PoroCYon
Shader_Minifier
Commits
b0da99f4
Commit
b0da99f4
authored
Jun 03, 2018
by
Laurent Le Brun
Browse files
Allow array declaration without size
float c[] = float[](3.14)
parent
d806a6e4
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/ast.fs
View file @
b0da99f4
...
...
@@ -33,7 +33,7 @@ type Expr =
|
Float
of
float
*
string
|
Var
of
Ident
|
FunCall
of
Expr
*
Expr
list
|
Subscript
of
Expr
*
Expr
|
Subscript
of
Expr
*
Expr
option
|
Dot
of
Expr
*
Ident
|
Cast
of
Ident
*
Expr
// hlsl
|
VectorExp
of
Expr
list
// hlsl
...
...
@@ -107,7 +107,7 @@ let rec mapExpr env = function
|
FunCall
(
fct
,
args
)
->
env
.
fExpr
env
(
FunCall
(
mapExpr
env
fct
,
List
.
map
(
mapExpr
env
)
args
))
|
Subscript
(
arr
,
ind
)
->
env
.
fExpr
env
(
Subscript
(
mapExpr
env
arr
,
mapExpr
env
ind
))
env
.
fExpr
env
(
Subscript
(
mapExpr
env
arr
,
Option
.
map
(
mapExpr
env
)
ind
))
|
Dot
(
e
,
field
)
->
env
.
fExpr
env
(
Dot
(
mapExpr
env
e
,
field
))
|
Cast
(
id
,
e
)
->
env
.
fExpr
env
(
Cast
(
id
,
mapExpr
env
e
))
|
VectorExp
(
li
)
->
...
...
src/parse.fs
View file @
b0da99f4
...
...
@@ -83,7 +83,7 @@ module private ParseImpl =
let
argList
=
sepBy
exprNoComma
(
ch
'
,
'
)
let
fcall
=
between
(
ch
'
(
'
)
(
ch
'
)
'
)
argList
|>>
(
fun
args
fct
->
Ast
.
FunCall
(
fct
,
args
))
let
subscript
=
between
(
ch
'
[
'
)
(
ch
'
]
'
)
expr
|>>
let
subscript
=
between
(
ch
'
[
'
)
(
ch
'
]
'
)
(
opt
expr
)
|>>
(
fun
ind
arr
->
Ast
.
Subscript
(
arr
,
ind
))
let
dot
=
ch
'.'
>>.
ident
|>>
(
fun
field
r
->
Ast
.
Dot
(
r
,
field
))
let
post
=
(
dot
<|>
subscript
<|>
fcall
)
<?>
""
...
...
src/printer.fs
View file @
b0da99f4
...
...
@@ -81,7 +81,7 @@ and exprToSLevel level = function
else
res
|
_
->
out
"%s(%s)"
(
exprToS
f
)
(
listToS
exprToS
","
args
)
|
Subscript
(
arr
,
ind
)
->
out
"%s[%s]"
(
exprToS
arr
)
(
exprToS
ind
)
out
"%s[%s]"
(
exprToS
arr
)
(
defaultArg
(
Option
.
map
exprToS
ind
)
""
)
|
Cast
(
id
,
e
)
->
// Cast seems to have the same precedence as unary minus
out
"(%s)%s"
id
(
exprToSLevel
precedence
.[
"_-"
]
e
)
...
...
tests/unit/array.frag
View file @
b0da99f4
...
...
@@ -4,3 +4,7 @@ float a[3+2] = float[5](3.4, 4.2, 5.0, 5.2, 1.1);
const
int
size
=
5
;
float
b
[
size
]
=
float
[
size
](
3
.
4
,
4
.
2
,
5
.
0
,
5
.
2
,
1
.
1
);
float
c
[]
=
float
[](
3
.
4
,
4
.
2
,
5
.
0
,
5
.
2
,
1
.
1
);
float
d
[
5
]
=
float
[](
3
.
4
,
4
.
2
,
5
.
0
,
5
.
2
,
1
.
1
);
float
e
[]
=
float
[
5
](
3
.
4
,
4
.
2
,
5
.
0
,
5
.
2
,
1
.
1
);
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment