Commit b0da99f4 authored by Laurent Le Brun's avatar Laurent Le Brun
Browse files

Allow array declaration without size

float c[] = float[](3.14)
parent d806a6e4
......@@ -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) ->
......
......@@ -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) <?> ""
......
......@@ -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)
......
......@@ -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);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment