public StructCompute ParseCompute(ref int i) { var rs = new StructCompute(); i++; rs.ComputeName = Get(i).Text; Console.WriteLine("Compute Name:" + rs.ComputeName); i++; for (i = i; i < toks.Len; i++) { var tok = Get(i); if (tok.Token == Token.Func) { var rt = Get(i + 1); if (rt.Text == ">") { var mf = new StructComputeFunc(); mf.FuncName = rs.ComputeName + "_main"; i++; mf.Code = ParseComputeCode(ref i); return(rs); } var fname = Get(i + 2).Text; i += 3; Console.WriteLine("ComputeFunc:" + fname + " ReturnType:" + rt.Text); var com_f = new StructComputeFunc(); com_f.FuncName = fname; rs.Funcs.Add(com_f); switch (rt.Text) { case "void": com_f.ReturnType = ComputeVarType.Void; break; case "vec3": com_f.ReturnType = ComputeVarType.Vec3; break; } if (Get(i).Token == Token.LeftPara) { Console.WriteLine("Parsing inputs"); i++; for (i = i; i < toks.Len; i++) { var var_t = Get(i); if (var_t.Token == Token.RightPara) { break; } var cv = new ComputeVar(); switch (var_t.Text) { case "vec3": cv.Type = ComputeVarType.Vec3; var v_name2 = Get(i + 1).Text; if (v_name2 == "*") { cv.Pointer = true; v_name2 = Get(i + 2).Text; i++; } i++; cv.Name = v_name2; com_f.InVars.Add(cv); break; case "int": cv.Type = ComputeVarType.Int; var v_name = Get(i + 1).Text; if (v_name == "*") { cv.Pointer = true; v_name = Get(i + 2).Text; i++; } i++; Console.WriteLine("int:" + v_name); cv.Name = v_name; com_f.InVars.Add(cv); break; default: foreach (var str in rs.Unique) { if (str.StructName == var_t.Text) { cv.Type = ComputeVarType.Struct; cv.StructName = str.StructName; var v_name3 = Get(i + 1).Text; if (v_name3 == "*") { cv.Pointer = true; v_name3 = Get(i + 2).Text; i++; } i++; cv.Name = v_name3; com_f.InVars.Add(cv); } } break; } } var com_c = ParseComputeCode(ref i); com_f.Code = com_c; } if (tok.Token == Token.End) { tok.Token = Token.BeginLine; break; } } if (tok.Token == Token.End) { return(rs); } if (tok.Token == Token.Id) { Console.WriteLine("Struct:" + tok.Text); StructComputeStruct str = null; foreach (var sr in ComStructs) { if (sr.StructName == tok.Text) { str = sr; } } str = str.Copy(); if (str == null) { Error(i, "Struct:" + tok.Text + " not found."); } var local_name = Get(i + 1).Text; i += 2; str.LocalName = local_name; bool is_in = false; switch (Get(i).Text) { case "in": is_in = true; rs.Inputs.Add(str); break; case "out": rs.Outputs.Add(str); break; } if (Get(i + 1).Text == "one") { str.One = true; i++; } bool found = false; foreach (var ts in rs.Unique) { if (ts.StructName == str.StructName) { found = true; } } if (!found) { rs.Unique.Add(str); } Console.WriteLine("Struct:" + str.StructName + " LocalName:" + str.LocalName + " In:" + is_in); } } return(rs); }
public StructComputeStruct ParseComputeStruct(ref int i) { var rs = new StructComputeStruct(); i++; rs.StructName = Get(i).Text; i++; if (Get(i).Text == "=") { i++; var tt = Get(i).Text; bool pointer = false; if (Get(i + 1).Text == "*") { pointer = true; } var var = new ComputeVar(); var.Name = rs.StructName; var.Pointer = pointer; rs.LinearData = true; switch (tt) { case "byte": var.Type = ComputeVarType.Byte; break; case "float": var.Type = ComputeVarType.Float; break; case "vec3": var.Type = ComputeVarType.Vec3; break; case "vec4": var.Type = ComputeVarType.Vec4; break; } rs.Vars.Add(var); i++; return(rs); } for (i = i; i < toks.Len; i++) { var tok = Get(i); switch (tok.Token) { case Token.End: return(rs); break; case Token.Byte: var byte1 = new ComputeVar(); byte1.Type = ComputeVarType.Byte; if (Get(i + 1).Text == "*") { byte1.Pointer = true; i++; } byte1.Name = Get(i + 1).Text; i += 2; rs.Vars.Add(byte1); break; case Token.Int: var int1 = new ComputeVar(); int1.Type = ComputeVarType.Int; if (Get(i + 1).Text == "*") { int1.Pointer = true; i++; } int1.Name = Get(i + 1).Text; i += 2; rs.Vars.Add(int1); break; case Token.Vec3: var vec3 = new ComputeVar(); vec3.Type = ComputeVarType.Vec3; if (Get(i + 1).Text == "*") { vec3.Pointer = true; i++; } vec3.Name = Get(i + 1).Text; i += 2; Console.WriteLine("CV:" + vec3.Name + " Type:" + vec3.Type.ToString()); rs.Vars.Add(vec3); break; } } return(rs); }