diff options
| -rw-r--r-- | source/slang/slang-reflection-json.cpp | 22 | ||||
| -rw-r--r-- | tests/reflection/attribute.slang | 8 | ||||
| -rw-r--r-- | tests/reflection/attribute.slang.expected | 257 |
3 files changed, 163 insertions, 124 deletions
diff --git a/source/slang/slang-reflection-json.cpp b/source/slang/slang-reflection-json.cpp index 82e8e1e3f..a84536f20 100644 --- a/source/slang/slang-reflection-json.cpp +++ b/source/slang/slang-reflection-json.cpp @@ -295,7 +295,7 @@ static void emitUserAttributeJSON(PrettyWriter& writer, slang::UserAttribute* us } else if (auto str = userAttribute->getArgumentValueString(i, &bufSize)) { - writer.write(str, bufSize); + writer.writeEscapedString(UnownedStringSlice(str, bufSize)); } else writer << "\"invalid value\""; @@ -303,7 +303,7 @@ static void emitUserAttributeJSON(PrettyWriter& writer, slang::UserAttribute* us writer.dedent(); writer << "\n]\n"; writer.dedent(); - writer << "}\n"; + writer << "}"; } static void emitUserAttributes(PrettyWriter& writer, slang::TypeReflection* type) @@ -311,7 +311,8 @@ static void emitUserAttributes(PrettyWriter& writer, slang::TypeReflection* type auto attribCount = type->getUserAttributeCount(); if (attribCount) { - writer << ",\n\"userAttribs\": ["; + writer << ",\n\"userAttribs\": [\n"; + writer.indent(); for (unsigned int i = 0; i < attribCount; i++) { if (i > 0) @@ -319,7 +320,8 @@ static void emitUserAttributes(PrettyWriter& writer, slang::TypeReflection* type auto attrib = type->getUserAttributeByIndex(i); emitUserAttributeJSON(writer, attrib); } - writer << "]"; + writer.dedent(); + writer << "\n]"; } } static void emitUserAttributes(PrettyWriter& writer, slang::VariableReflection* var) @@ -327,7 +329,8 @@ static void emitUserAttributes(PrettyWriter& writer, slang::VariableReflection* auto attribCount = var->getUserAttributeCount(); if (attribCount) { - writer << ",\n\"userAttribs\": ["; + writer << ",\n\"userAttribs\": [\n"; + writer.indent(); for (unsigned int i = 0; i < attribCount; i++) { if (i > 0) @@ -335,7 +338,8 @@ static void emitUserAttributes(PrettyWriter& writer, slang::VariableReflection* auto attrib = var->getUserAttributeByIndex(i); emitUserAttributeJSON(writer, attrib); } - writer << "]"; + writer.dedent(); + writer << "\n]"; } } static void emitUserAttributes(PrettyWriter& writer, slang::FunctionReflection* func) @@ -343,7 +347,8 @@ static void emitUserAttributes(PrettyWriter& writer, slang::FunctionReflection* auto attribCount = func->getUserAttributeCount(); if (attribCount) { - writer << ",\n\"userAttribs\": ["; + writer << ",\n\"userAttribs\": [\n"; + writer.indent(); for (unsigned int i = 0; i < attribCount; i++) { if (i > 0) @@ -351,7 +356,8 @@ static void emitUserAttributes(PrettyWriter& writer, slang::FunctionReflection* auto attrib = func->getUserAttributeByIndex(i); emitUserAttributeJSON(writer, attrib); } - writer << "]"; + writer.dedent(); + writer << "\n]"; } } diff --git a/tests/reflection/attribute.slang b/tests/reflection/attribute.slang index 0157f67d0..8d755648a 100644 --- a/tests/reflection/attribute.slang +++ b/tests/reflection/attribute.slang @@ -10,6 +10,7 @@ struct MyStructAttribute { int iParam; float fParam; + string sParam; }; [__AttributeUsage(_AttributeTargets.Var)] @@ -19,7 +20,7 @@ struct DefaultValueAttribute int iParam; }; -[MyStruct(0, 1.0)] +[MyStruct(0, 1.0, "A")] struct A { float x; @@ -27,7 +28,7 @@ struct A float y; }; -[MyStruct(0, 2.0)] +[MyStruct(0, 2.0, "\"")] struct B { float x; @@ -59,7 +60,8 @@ D param3; [StructVarParam(1)] int globalInt2; -[MyStruct(2, 3.0)] +[MyStruct(2, 3.0, "main")] +[MyStruct(-2, -3.0, "")] [numthreads(1, 1, 1)] void main( uint3 dispatchThreadID : SV_DispatchThreadID, diff --git a/tests/reflection/attribute.slang.expected b/tests/reflection/attribute.slang.expected index 978d43d43..665d0b367 100644 --- a/tests/reflection/attribute.slang.expected +++ b/tests/reflection/attribute.slang.expected @@ -27,30 +27,34 @@ standard output = { "kind": "scalar", "scalarType": "float32" }, - "userAttribs": [{ - "name": "DefaultValue", - "arguments": [ - 1 - ] - } + "userAttribs": [ + { + "name": "DefaultValue", + "arguments": [ + 1 + ] + } ], "binding": {"kind": "uniform", "offset": 4, "size": 4}, - "userAttribs": [{ - "name": "DefaultValue", - "arguments": [ - 1 - ] - } + "userAttribs": [ + { + "name": "DefaultValue", + "arguments": [ + 1 + ] + } ] } ], - "userAttribs": [{ - "name": "MyStruct", - "arguments": [ - 0, - 1.000000 - ] - } + "userAttribs": [ + { + "name": "MyStruct", + "arguments": [ + 0, + 1.000000, + "A" + ] + } ] }, "containerVarLayout": { @@ -75,30 +79,34 @@ standard output = { "kind": "scalar", "scalarType": "float32" }, - "userAttribs": [{ - "name": "DefaultValue", - "arguments": [ - 1 - ] - } + "userAttribs": [ + { + "name": "DefaultValue", + "arguments": [ + 1 + ] + } ], "binding": {"kind": "uniform", "offset": 4, "size": 4}, - "userAttribs": [{ - "name": "DefaultValue", - "arguments": [ - 1 - ] - } + "userAttribs": [ + { + "name": "DefaultValue", + "arguments": [ + 1 + ] + } ] } ], - "userAttribs": [{ - "name": "MyStruct", - "arguments": [ - 0, - 1.000000 - ] - } + "userAttribs": [ + { + "name": "MyStruct", + "arguments": [ + 0, + 1.000000, + "A" + ] + } ] }, "binding": {"kind": "uniform", "offset": 0, "size": 8} @@ -128,30 +136,34 @@ standard output = { "kind": "scalar", "scalarType": "float32" }, - "userAttribs": [{ - "name": "DefaultValue", - "arguments": [ - 2 - ] - } + "userAttribs": [ + { + "name": "DefaultValue", + "arguments": [ + 2 + ] + } ], "binding": {"kind": "uniform", "offset": 4, "size": 4}, - "userAttribs": [{ - "name": "DefaultValue", - "arguments": [ - 2 - ] - } + "userAttribs": [ + { + "name": "DefaultValue", + "arguments": [ + 2 + ] + } ] } ], - "userAttribs": [{ - "name": "MyStruct", - "arguments": [ - 0, - 2.000000 - ] - } + "userAttribs": [ + { + "name": "MyStruct", + "arguments": [ + 0, + 2.000000, + "\"" + ] + } ] }, "containerVarLayout": { @@ -176,30 +188,34 @@ standard output = { "kind": "scalar", "scalarType": "float32" }, - "userAttribs": [{ - "name": "DefaultValue", - "arguments": [ - 2 - ] - } + "userAttribs": [ + { + "name": "DefaultValue", + "arguments": [ + 2 + ] + } ], "binding": {"kind": "uniform", "offset": 4, "size": 4}, - "userAttribs": [{ - "name": "DefaultValue", - "arguments": [ - 2 - ] - } + "userAttribs": [ + { + "name": "DefaultValue", + "arguments": [ + 2 + ] + } ] } ], - "userAttribs": [{ - "name": "MyStruct", - "arguments": [ - 0, - 2.000000 - ] - } + "userAttribs": [ + { + "name": "MyStruct", + "arguments": [ + 0, + 2.000000, + "\"" + ] + } ] }, "binding": {"kind": "uniform", "offset": 0, "size": 8} @@ -208,12 +224,13 @@ standard output = { }, { "name": "globalInt", - "userAttribs": [{ - "name": "DefaultValue", - "arguments": [ - 2 - ] - } + "userAttribs": [ + { + "name": "DefaultValue", + "arguments": [ + 2 + ] + } ], "binding": {"kind": "uniform", "offset": 0, "size": 4}, "type": { @@ -237,23 +254,25 @@ standard output = { "binding": {"kind": "uniform", "offset": 0, "size": 4} } ], - "userAttribs": [{ - "name": "StructVarParam", - "arguments": [ - 0 - ] - } + "userAttribs": [ + { + "name": "StructVarParam", + "arguments": [ + 0 + ] + } ] } }, { "name": "globalInt2", - "userAttribs": [{ - "name": "StructVarParam", - "arguments": [ - 1 - ] - } + "userAttribs": [ + { + "name": "StructVarParam", + "arguments": [ + 1 + ] + } ], "binding": {"kind": "uniform", "offset": 20, "size": 4}, "type": { @@ -281,12 +300,13 @@ standard output = { }, { "name": "a", - "userAttribs": [{ - "name": "DefaultValue", - "arguments": [ - 3 - ] - } + "userAttribs": [ + { + "name": "DefaultValue", + "arguments": [ + 3 + ] + } ], "binding": {"kind": "uniform", "offset": 0, "size": 4}, "type": { @@ -296,12 +316,13 @@ standard output = { }, { "name": "b", - "userAttribs": [{ - "name": "StructVarParam", - "arguments": [ - 2 - ] - } + "userAttribs": [ + { + "name": "StructVarParam", + "arguments": [ + 2 + ] + } ], "binding": {"kind": "uniform", "offset": 4, "size": 4}, "type": { @@ -311,13 +332,23 @@ standard output = { } ], "threadGroupSize": [1, 1, 1], - "userAttribs": [{ - "name": "MyStruct", - "arguments": [ - 2, - 3.000000 - ] - } + "userAttribs": [ + { + "name": "MyStruct", + "arguments": [ + 2, + 3.000000, + "main" + ] + }, + { + "name": "MyStruct", + "arguments": [ + -2, + -3.000000, + "" + ] + } ] } ] |
