diff options
| -rw-r--r-- | premake5.lua | 4 | ||||
| -rw-r--r-- | slang.h | 2 | ||||
| -rw-r--r-- | slang.sln | 164 | ||||
| -rw-r--r-- | source/core/core.vcxproj | 2 | ||||
| -rw-r--r-- | source/core/core.vcxproj.filters | 4 | ||||
| -rw-r--r-- | source/core/slang-io.cpp | 99 | ||||
| -rw-r--r-- | source/core/slang-io.h | 11 | ||||
| -rw-r--r-- | source/core/slang-string-util.cpp | 37 | ||||
| -rw-r--r-- | source/core/slang-string-util.h | 41 | ||||
| -rw-r--r-- | source/slang/compiler.cpp | 4 | ||||
| -rw-r--r-- | source/slang/compiler.h | 5 | ||||
| -rw-r--r-- | source/slang/default-file-system.cpp | 127 | ||||
| -rw-r--r-- | source/slang/default-file-system.h | 104 | ||||
| -rw-r--r-- | source/slang/preprocessor.cpp | 2 | ||||
| -rw-r--r-- | source/slang/slang-file-system.cpp | 275 | ||||
| -rw-r--r-- | source/slang/slang-file-system.h | 161 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 71 | ||||
| -rw-r--r-- | source/slang/slang.vcxproj | 14 | ||||
| -rw-r--r-- | source/slang/slang.vcxproj.filters | 22 | ||||
| -rw-r--r-- | source/slang/source-loc.cpp | 4 | ||||
| -rw-r--r-- | tests/front-end/import-subdir-search-path.slang | 3 | ||||
| -rw-r--r-- | tools/slang-test/unit-test-path.cpp | 15 |
22 files changed, 767 insertions, 404 deletions
diff --git a/premake5.lua b/premake5.lua index d1b33425e..7f83c8904 100644 --- a/premake5.lua +++ b/premake5.lua @@ -53,8 +53,8 @@ workspace "slang" configurations { "Debug", "Release" } platforms { "x86", "x64" } - filter { "system:linux" } - location("build.linux") + --filter { "system:linux" } + -- location("build.linux") -- The output binary directory will be derived from the OS -- and configuration options, e.g. `bin/windows-x64/debug/` @@ -535,7 +535,7 @@ extern "C" //! Get the result code for the facility #define SLANG_GET_RESULT_CODE(r) ((int32_t)((r) & 0xffff)) -#define SLANG_MAKE_ERROR(fac, code) ((((int32_t)(fac)) << 16) | ((int32_t)(code)) | 0x80000000) +#define SLANG_MAKE_ERROR(fac, code) ((((int32_t)(fac)) << 16) | ((int32_t)(code)) | int32_t(0x80000000)) #define SLANG_MAKE_SUCCESS(fac, code) ((((int32_t)(fac)) << 16) | ((int32_t)(code))) /*************************** Facilities ************************************/ @@ -1,36 +1,36 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "core", "source\core\core.vcxproj", "{F9BE7957-8399-899E-0C49-E714FDDD4B65}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{EB5FC2C6-D72D-B6CC-C0C1-26F3AC2E9231}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hello-world", "examples\hello-world\hello-world.vcxproj", "{5CF41E7B-4883-A844-F1A1-BC3FDD0FB9EA}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "model-viewer", "examples\model-viewer\model-viewer.vcxproj", "{639B13F2-CF07-CFEC-98FB-664A0427F154}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slang", "source\slang\slang.vcxproj", "{DB00DA62-0533-4AFD-B59F-A67D5B3A0808}" - ProjectSection(ProjectDependencies) = postProject - {66174227-8541-41FC-A6DF-4764FC66F78E} = {66174227-8541-41FC-A6DF-4764FC66F78E} - EndProjectSection +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "core", "source\core\core.vcxproj", "{F9BE7957-8399-899E-0C49-E714FDDD4B65}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slang-glslang", "source\slang-glslang\slang-glslang.vcxproj", "{C495878A-832C-485B-B347-0998A90CC936}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{FD47AE19-69FD-260F-F2F1-20E65EA61D13}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slangc", "source\slangc\slangc.vcxproj", "{D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slang-generate", "tools\slang-generate\slang-generate.vcxproj", "{66174227-8541-41FC-A6DF-4764FC66F78E}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{FD47AE19-69FD-260F-F2F1-20E65EA61D13}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slang-test", "tools\slang-test\slang-test.vcxproj", "{0C768A18-1D25-4000-9F37-DA5FE99E3B64}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gfx", "tools\gfx\gfx.vcxproj", "{222F7498-B40C-4F3F-A704-DDEB91A4484A}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slang-reflection-test", "tools\slang-reflection-test\slang-reflection-test.vcxproj", "{22C45F4F-FB6B-4535-BED1-D3F5D0C71047}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slang-eval-test", "tools\slang-eval-test\slang-eval-test.vcxproj", "{205FCAB9-A13F-4980-86FA-F6221A7095EE}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "render-test", "tools\render-test\render-test.vcxproj", "{96610759-07B9-4EEB-A974-5C634A2E742B}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slang-eval-test", "tools\slang-eval-test\slang-eval-test.vcxproj", "{205FCAB9-A13F-4980-86FA-F6221A7095EE}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gfx", "tools\gfx\gfx.vcxproj", "{222F7498-B40C-4F3F-A704-DDEB91A4484A}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slang-generate", "tools\slang-generate\slang-generate.vcxproj", "{66174227-8541-41FC-A6DF-4764FC66F78E}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slangc", "source\slangc\slangc.vcxproj", "{D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slang-reflection-test", "tools\slang-reflection-test\slang-reflection-test.vcxproj", "{22C45F4F-FB6B-4535-BED1-D3F5D0C71047}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slang", "source\slang\slang.vcxproj", "{DB00DA62-0533-4AFD-B59F-A67D5B3A0808}" + ProjectSection(ProjectDependencies) = postProject + {66174227-8541-41FC-A6DF-4764FC66F78E} = {66174227-8541-41FC-A6DF-4764FC66F78E} + EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slang-test", "tools\slang-test\slang-test.vcxproj", "{0C768A18-1D25-4000-9F37-DA5FE99E3B64}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slang-glslang", "source\slang-glslang\slang-glslang.vcxproj", "{C495878A-832C-485B-B347-0998A90CC936}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -40,14 +40,6 @@ Global Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {F9BE7957-8399-899E-0C49-E714FDDD4B65}.Debug|Win32.ActiveCfg = Debug|Win32 - {F9BE7957-8399-899E-0C49-E714FDDD4B65}.Debug|Win32.Build.0 = Debug|Win32 - {F9BE7957-8399-899E-0C49-E714FDDD4B65}.Debug|x64.ActiveCfg = Debug|x64 - {F9BE7957-8399-899E-0C49-E714FDDD4B65}.Debug|x64.Build.0 = Debug|x64 - {F9BE7957-8399-899E-0C49-E714FDDD4B65}.Release|Win32.ActiveCfg = Release|Win32 - {F9BE7957-8399-899E-0C49-E714FDDD4B65}.Release|Win32.Build.0 = Release|Win32 - {F9BE7957-8399-899E-0C49-E714FDDD4B65}.Release|x64.ActiveCfg = Release|x64 - {F9BE7957-8399-899E-0C49-E714FDDD4B65}.Release|x64.Build.0 = Release|x64 {5CF41E7B-4883-A844-F1A1-BC3FDD0FB9EA}.Debug|Win32.ActiveCfg = Debug|Win32 {5CF41E7B-4883-A844-F1A1-BC3FDD0FB9EA}.Debug|Win32.Build.0 = Debug|Win32 {5CF41E7B-4883-A844-F1A1-BC3FDD0FB9EA}.Debug|x64.ActiveCfg = Debug|x64 @@ -64,54 +56,14 @@ Global {639B13F2-CF07-CFEC-98FB-664A0427F154}.Release|Win32.Build.0 = Release|Win32 {639B13F2-CF07-CFEC-98FB-664A0427F154}.Release|x64.ActiveCfg = Release|x64 {639B13F2-CF07-CFEC-98FB-664A0427F154}.Release|x64.Build.0 = Release|x64 - {DB00DA62-0533-4AFD-B59F-A67D5B3A0808}.Debug|Win32.ActiveCfg = Debug|Win32 - {DB00DA62-0533-4AFD-B59F-A67D5B3A0808}.Debug|Win32.Build.0 = Debug|Win32 - {DB00DA62-0533-4AFD-B59F-A67D5B3A0808}.Debug|x64.ActiveCfg = Debug|x64 - {DB00DA62-0533-4AFD-B59F-A67D5B3A0808}.Debug|x64.Build.0 = Debug|x64 - {DB00DA62-0533-4AFD-B59F-A67D5B3A0808}.Release|Win32.ActiveCfg = Release|Win32 - {DB00DA62-0533-4AFD-B59F-A67D5B3A0808}.Release|Win32.Build.0 = Release|Win32 - {DB00DA62-0533-4AFD-B59F-A67D5B3A0808}.Release|x64.ActiveCfg = Release|x64 - {DB00DA62-0533-4AFD-B59F-A67D5B3A0808}.Release|x64.Build.0 = Release|x64 - {C495878A-832C-485B-B347-0998A90CC936}.Debug|Win32.ActiveCfg = Debug|Win32 - {C495878A-832C-485B-B347-0998A90CC936}.Debug|Win32.Build.0 = Debug|Win32 - {C495878A-832C-485B-B347-0998A90CC936}.Debug|x64.ActiveCfg = Debug|x64 - {C495878A-832C-485B-B347-0998A90CC936}.Debug|x64.Build.0 = Debug|x64 - {C495878A-832C-485B-B347-0998A90CC936}.Release|Win32.ActiveCfg = Release|Win32 - {C495878A-832C-485B-B347-0998A90CC936}.Release|Win32.Build.0 = Release|Win32 - {C495878A-832C-485B-B347-0998A90CC936}.Release|x64.ActiveCfg = Release|x64 - {C495878A-832C-485B-B347-0998A90CC936}.Release|x64.Build.0 = Release|x64 - {D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}.Debug|Win32.ActiveCfg = Debug|Win32 - {D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}.Debug|Win32.Build.0 = Debug|Win32 - {D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}.Debug|x64.ActiveCfg = Debug|x64 - {D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}.Debug|x64.Build.0 = Debug|x64 - {D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}.Release|Win32.ActiveCfg = Release|Win32 - {D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}.Release|Win32.Build.0 = Release|Win32 - {D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}.Release|x64.ActiveCfg = Release|x64 - {D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}.Release|x64.Build.0 = Release|x64 - {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Debug|Win32.ActiveCfg = Debug|Win32 - {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Debug|Win32.Build.0 = Debug|Win32 - {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Debug|x64.ActiveCfg = Debug|x64 - {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Debug|x64.Build.0 = Debug|x64 - {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Release|Win32.ActiveCfg = Release|Win32 - {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Release|Win32.Build.0 = Release|Win32 - {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Release|x64.ActiveCfg = Release|x64 - {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Release|x64.Build.0 = Release|x64 - {96610759-07B9-4EEB-A974-5C634A2E742B}.Debug|Win32.ActiveCfg = Debug|Win32 - {96610759-07B9-4EEB-A974-5C634A2E742B}.Debug|Win32.Build.0 = Debug|Win32 - {96610759-07B9-4EEB-A974-5C634A2E742B}.Debug|x64.ActiveCfg = Debug|x64 - {96610759-07B9-4EEB-A974-5C634A2E742B}.Debug|x64.Build.0 = Debug|x64 - {96610759-07B9-4EEB-A974-5C634A2E742B}.Release|Win32.ActiveCfg = Release|Win32 - {96610759-07B9-4EEB-A974-5C634A2E742B}.Release|Win32.Build.0 = Release|Win32 - {96610759-07B9-4EEB-A974-5C634A2E742B}.Release|x64.ActiveCfg = Release|x64 - {96610759-07B9-4EEB-A974-5C634A2E742B}.Release|x64.Build.0 = Release|x64 - {205FCAB9-A13F-4980-86FA-F6221A7095EE}.Debug|Win32.ActiveCfg = Debug|Win32 - {205FCAB9-A13F-4980-86FA-F6221A7095EE}.Debug|Win32.Build.0 = Debug|Win32 - {205FCAB9-A13F-4980-86FA-F6221A7095EE}.Debug|x64.ActiveCfg = Debug|x64 - {205FCAB9-A13F-4980-86FA-F6221A7095EE}.Debug|x64.Build.0 = Debug|x64 - {205FCAB9-A13F-4980-86FA-F6221A7095EE}.Release|Win32.ActiveCfg = Release|Win32 - {205FCAB9-A13F-4980-86FA-F6221A7095EE}.Release|Win32.Build.0 = Release|Win32 - {205FCAB9-A13F-4980-86FA-F6221A7095EE}.Release|x64.ActiveCfg = Release|x64 - {205FCAB9-A13F-4980-86FA-F6221A7095EE}.Release|x64.Build.0 = Release|x64 + {F9BE7957-8399-899E-0C49-E714FDDD4B65}.Debug|Win32.ActiveCfg = Debug|Win32 + {F9BE7957-8399-899E-0C49-E714FDDD4B65}.Debug|Win32.Build.0 = Debug|Win32 + {F9BE7957-8399-899E-0C49-E714FDDD4B65}.Debug|x64.ActiveCfg = Debug|x64 + {F9BE7957-8399-899E-0C49-E714FDDD4B65}.Debug|x64.Build.0 = Debug|x64 + {F9BE7957-8399-899E-0C49-E714FDDD4B65}.Release|Win32.ActiveCfg = Release|Win32 + {F9BE7957-8399-899E-0C49-E714FDDD4B65}.Release|Win32.Build.0 = Release|Win32 + {F9BE7957-8399-899E-0C49-E714FDDD4B65}.Release|x64.ActiveCfg = Release|x64 + {F9BE7957-8399-899E-0C49-E714FDDD4B65}.Release|x64.Build.0 = Release|x64 {66174227-8541-41FC-A6DF-4764FC66F78E}.Debug|Win32.ActiveCfg = Debug|Win32 {66174227-8541-41FC-A6DF-4764FC66F78E}.Debug|Win32.Build.0 = Debug|Win32 {66174227-8541-41FC-A6DF-4764FC66F78E}.Debug|x64.ActiveCfg = Debug|x64 @@ -120,14 +72,6 @@ Global {66174227-8541-41FC-A6DF-4764FC66F78E}.Release|Win32.Build.0 = Release|Win32 {66174227-8541-41FC-A6DF-4764FC66F78E}.Release|x64.ActiveCfg = Release|x64 {66174227-8541-41FC-A6DF-4764FC66F78E}.Release|x64.Build.0 = Release|x64 - {22C45F4F-FB6B-4535-BED1-D3F5D0C71047}.Debug|Win32.ActiveCfg = Debug|Win32 - {22C45F4F-FB6B-4535-BED1-D3F5D0C71047}.Debug|Win32.Build.0 = Debug|Win32 - {22C45F4F-FB6B-4535-BED1-D3F5D0C71047}.Debug|x64.ActiveCfg = Debug|x64 - {22C45F4F-FB6B-4535-BED1-D3F5D0C71047}.Debug|x64.Build.0 = Debug|x64 - {22C45F4F-FB6B-4535-BED1-D3F5D0C71047}.Release|Win32.ActiveCfg = Release|Win32 - {22C45F4F-FB6B-4535-BED1-D3F5D0C71047}.Release|Win32.Build.0 = Release|Win32 - {22C45F4F-FB6B-4535-BED1-D3F5D0C71047}.Release|x64.ActiveCfg = Release|x64 - {22C45F4F-FB6B-4535-BED1-D3F5D0C71047}.Release|x64.Build.0 = Release|x64 {0C768A18-1D25-4000-9F37-DA5FE99E3B64}.Debug|Win32.ActiveCfg = Debug|Win32 {0C768A18-1D25-4000-9F37-DA5FE99E3B64}.Debug|Win32.Build.0 = Debug|Win32 {0C768A18-1D25-4000-9F37-DA5FE99E3B64}.Debug|x64.ActiveCfg = Debug|x64 @@ -136,6 +80,62 @@ Global {0C768A18-1D25-4000-9F37-DA5FE99E3B64}.Release|Win32.Build.0 = Release|Win32 {0C768A18-1D25-4000-9F37-DA5FE99E3B64}.Release|x64.ActiveCfg = Release|x64 {0C768A18-1D25-4000-9F37-DA5FE99E3B64}.Release|x64.Build.0 = Release|x64 + {22C45F4F-FB6B-4535-BED1-D3F5D0C71047}.Debug|Win32.ActiveCfg = Debug|Win32 + {22C45F4F-FB6B-4535-BED1-D3F5D0C71047}.Debug|Win32.Build.0 = Debug|Win32 + {22C45F4F-FB6B-4535-BED1-D3F5D0C71047}.Debug|x64.ActiveCfg = Debug|x64 + {22C45F4F-FB6B-4535-BED1-D3F5D0C71047}.Debug|x64.Build.0 = Debug|x64 + {22C45F4F-FB6B-4535-BED1-D3F5D0C71047}.Release|Win32.ActiveCfg = Release|Win32 + {22C45F4F-FB6B-4535-BED1-D3F5D0C71047}.Release|Win32.Build.0 = Release|Win32 + {22C45F4F-FB6B-4535-BED1-D3F5D0C71047}.Release|x64.ActiveCfg = Release|x64 + {22C45F4F-FB6B-4535-BED1-D3F5D0C71047}.Release|x64.Build.0 = Release|x64 + {205FCAB9-A13F-4980-86FA-F6221A7095EE}.Debug|Win32.ActiveCfg = Debug|Win32 + {205FCAB9-A13F-4980-86FA-F6221A7095EE}.Debug|Win32.Build.0 = Debug|Win32 + {205FCAB9-A13F-4980-86FA-F6221A7095EE}.Debug|x64.ActiveCfg = Debug|x64 + {205FCAB9-A13F-4980-86FA-F6221A7095EE}.Debug|x64.Build.0 = Debug|x64 + {205FCAB9-A13F-4980-86FA-F6221A7095EE}.Release|Win32.ActiveCfg = Release|Win32 + {205FCAB9-A13F-4980-86FA-F6221A7095EE}.Release|Win32.Build.0 = Release|Win32 + {205FCAB9-A13F-4980-86FA-F6221A7095EE}.Release|x64.ActiveCfg = Release|x64 + {205FCAB9-A13F-4980-86FA-F6221A7095EE}.Release|x64.Build.0 = Release|x64 + {96610759-07B9-4EEB-A974-5C634A2E742B}.Debug|Win32.ActiveCfg = Debug|Win32 + {96610759-07B9-4EEB-A974-5C634A2E742B}.Debug|Win32.Build.0 = Debug|Win32 + {96610759-07B9-4EEB-A974-5C634A2E742B}.Debug|x64.ActiveCfg = Debug|x64 + {96610759-07B9-4EEB-A974-5C634A2E742B}.Debug|x64.Build.0 = Debug|x64 + {96610759-07B9-4EEB-A974-5C634A2E742B}.Release|Win32.ActiveCfg = Release|Win32 + {96610759-07B9-4EEB-A974-5C634A2E742B}.Release|Win32.Build.0 = Release|Win32 + {96610759-07B9-4EEB-A974-5C634A2E742B}.Release|x64.ActiveCfg = Release|x64 + {96610759-07B9-4EEB-A974-5C634A2E742B}.Release|x64.Build.0 = Release|x64 + {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Debug|Win32.ActiveCfg = Debug|Win32 + {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Debug|Win32.Build.0 = Debug|Win32 + {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Debug|x64.ActiveCfg = Debug|x64 + {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Debug|x64.Build.0 = Debug|x64 + {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Release|Win32.ActiveCfg = Release|Win32 + {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Release|Win32.Build.0 = Release|Win32 + {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Release|x64.ActiveCfg = Release|x64 + {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Release|x64.Build.0 = Release|x64 + {D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}.Debug|Win32.ActiveCfg = Debug|Win32 + {D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}.Debug|Win32.Build.0 = Debug|Win32 + {D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}.Debug|x64.ActiveCfg = Debug|x64 + {D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}.Debug|x64.Build.0 = Debug|x64 + {D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}.Release|Win32.ActiveCfg = Release|Win32 + {D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}.Release|Win32.Build.0 = Release|Win32 + {D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}.Release|x64.ActiveCfg = Release|x64 + {D56CBCEB-1EB5-4CA8-AEC4-48EA35ED61C7}.Release|x64.Build.0 = Release|x64 + {DB00DA62-0533-4AFD-B59F-A67D5B3A0808}.Debug|Win32.ActiveCfg = Debug|Win32 + {DB00DA62-0533-4AFD-B59F-A67D5B3A0808}.Debug|Win32.Build.0 = Debug|Win32 + {DB00DA62-0533-4AFD-B59F-A67D5B3A0808}.Debug|x64.ActiveCfg = Debug|x64 + {DB00DA62-0533-4AFD-B59F-A67D5B3A0808}.Debug|x64.Build.0 = Debug|x64 + {DB00DA62-0533-4AFD-B59F-A67D5B3A0808}.Release|Win32.ActiveCfg = Release|Win32 + {DB00DA62-0533-4AFD-B59F-A67D5B3A0808}.Release|Win32.Build.0 = Release|Win32 + {DB00DA62-0533-4AFD-B59F-A67D5B3A0808}.Release|x64.ActiveCfg = Release|x64 + {DB00DA62-0533-4AFD-B59F-A67D5B3A0808}.Release|x64.Build.0 = Release|x64 + {C495878A-832C-485B-B347-0998A90CC936}.Debug|Win32.ActiveCfg = Debug|Win32 + {C495878A-832C-485B-B347-0998A90CC936}.Debug|Win32.Build.0 = Debug|Win32 + {C495878A-832C-485B-B347-0998A90CC936}.Debug|x64.ActiveCfg = Debug|x64 + {C495878A-832C-485B-B347-0998A90CC936}.Debug|x64.Build.0 = Debug|x64 + {C495878A-832C-485B-B347-0998A90CC936}.Release|Win32.ActiveCfg = Release|Win32 + {C495878A-832C-485B-B347-0998A90CC936}.Release|Win32.Build.0 = Release|Win32 + {C495878A-832C-485B-B347-0998A90CC936}.Release|x64.ActiveCfg = Release|x64 + {C495878A-832C-485B-B347-0998A90CC936}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -143,11 +143,11 @@ Global GlobalSection(NestedProjects) = preSolution {5CF41E7B-4883-A844-F1A1-BC3FDD0FB9EA} = {EB5FC2C6-D72D-B6CC-C0C1-26F3AC2E9231} {639B13F2-CF07-CFEC-98FB-664A0427F154} = {EB5FC2C6-D72D-B6CC-C0C1-26F3AC2E9231} - {222F7498-B40C-4F3F-A704-DDEB91A4484A} = {FD47AE19-69FD-260F-F2F1-20E65EA61D13} - {96610759-07B9-4EEB-A974-5C634A2E742B} = {FD47AE19-69FD-260F-F2F1-20E65EA61D13} - {205FCAB9-A13F-4980-86FA-F6221A7095EE} = {FD47AE19-69FD-260F-F2F1-20E65EA61D13} {66174227-8541-41FC-A6DF-4764FC66F78E} = {FD47AE19-69FD-260F-F2F1-20E65EA61D13} - {22C45F4F-FB6B-4535-BED1-D3F5D0C71047} = {FD47AE19-69FD-260F-F2F1-20E65EA61D13} {0C768A18-1D25-4000-9F37-DA5FE99E3B64} = {FD47AE19-69FD-260F-F2F1-20E65EA61D13} + {22C45F4F-FB6B-4535-BED1-D3F5D0C71047} = {FD47AE19-69FD-260F-F2F1-20E65EA61D13} + {205FCAB9-A13F-4980-86FA-F6221A7095EE} = {FD47AE19-69FD-260F-F2F1-20E65EA61D13} + {96610759-07B9-4EEB-A974-5C634A2E742B} = {FD47AE19-69FD-260F-F2F1-20E65EA61D13} + {222F7498-B40C-4F3F-A704-DDEB91A4484A} = {FD47AE19-69FD-260F-F2F1-20E65EA61D13} EndGlobalSection EndGlobal diff --git a/source/core/core.vcxproj b/source/core/core.vcxproj index d1ed4715f..2d0c67342 100644 --- a/source/core/core.vcxproj +++ b/source/core/core.vcxproj @@ -213,7 +213,7 @@ <ClCompile Include="token-reader.cpp" /> </ItemGroup> <ItemGroup> - <Natvis Include="core.natvis" /> + <None Include="core.natvis" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/source/core/core.vcxproj.filters b/source/core/core.vcxproj.filters index 7936ca11b..1548217b4 100644 --- a/source/core/core.vcxproj.filters +++ b/source/core/core.vcxproj.filters @@ -130,8 +130,8 @@ </ClCompile> </ItemGroup> <ItemGroup> - <Natvis Include="core.natvis"> + <None Include="core.natvis"> <Filter>Source Files</Filter> - </Natvis> + </None> </ItemGroup> </Project>
\ No newline at end of file diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index 2b443a62b..f1948200c 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -123,6 +123,105 @@ namespace Slang return sb.ProduceString(); } + /* static */ bool Path::IsDriveSpecification(const UnownedStringSlice& element) + { + switch (element.size()) + { + case 0: + { + // We'll just assume it is + return true; + } + case 2: + { + // Look for a windows like drive spec + const char firstChar = element[0]; + return element[1] == ':' && ((firstChar >= 'a' && firstChar <= 'z') || (firstChar >= 'A' && firstChar <= 'Z')); + } + default: return false; + } + + } + + /* static */void Path::Split(const UnownedStringSlice& path, List<UnownedStringSlice>& splitOut) + { + splitOut.Clear(); + + const char* start = path.begin(); + const char* end = path.end(); + + while (start < end) + { + const char* cur = start; + // Find the split + while (cur < end && !IsDelimiter(*cur)) cur++; + + splitOut.Add(UnownedStringSlice(start, cur)); + + // Next + start = cur + 1; + } + + // Okay if the end is empty. And we aren't with a spec like // or c:/ , then drop the final slash + if (splitOut.Count() > 1 && splitOut.Last().size() == 0) + { + if (splitOut.Count() == 2 && IsDriveSpecification(splitOut[0])) + { + return; + } + // Remove the last + splitOut.RemoveLast(); + } + } + + /* static */String Path::Simplify(const UnownedStringSlice& path) + { + List<UnownedStringSlice> split; + Split(path, split); + + // Strictly speaking we could do something about case on platforms like window, but here we won't worry about that + for (int i = 0; i < int(split.Count()); i++) + { + const UnownedStringSlice& cur = split[i]; + if (cur == "." && split.Count() > 1) + { + // Just remove it + split.RemoveAt(i); + i--; + } + else if (cur == ".." && i > 0) + { + // Can we remove this and the one before ? + UnownedStringSlice& before = split[i - 1]; + if (before == ".." || (i == 1 && IsDriveSpecification(before))) + { + // Can't do it + continue; + } + split.RemoveRange(i - 1, 2); + i -= 2; + } + } + + // If its empty it must be . + if (split.Count() == 0) + { + split.Add(UnownedStringSlice::fromLiteral(".")); + } + + // Reconstruct the string + StringBuilder builder; + for (int i = 0; i < int(split.Count()); i++) + { + if (i > 0) + { + builder.Append(PathDelimiter); + } + builder.Append(split[i]); + } + return builder; + } + bool Path::CreateDir(const String & path) { #if defined(_WIN32) diff --git a/source/core/slang-io.h b/source/core/slang-io.h index ff287254c..3703aee08 100644 --- a/source/core/slang-io.h +++ b/source/core/slang-io.h @@ -32,6 +32,17 @@ namespace Slang static String Combine(const String & path1, const String & path2, const String & path3); static bool CreateDir(const String & path); + /// Accept either style of delimiter + SLANG_FORCE_INLINE static bool IsDelimiter(char c) { return c == '/' || c == '\\'; } + + static bool IsDriveSpecification(const UnownedStringSlice& element); + + /// Splits the path into it's individual bits + static void Split(const UnownedStringSlice& path, List<UnownedStringSlice>& splitOut); + /// Strips .. and . as much as it can + static String Simplify(const UnownedStringSlice& path); + static String Simplify(const String& path) { return Simplify(path.getUnownedSlice()); } + static SlangResult GetPathType(const String & path, SlangPathType* pathTypeOut); static SlangResult GetCanonical(const String & path, String& canonicalPathOut); diff --git a/source/core/slang-string-util.cpp b/source/core/slang-string-util.cpp index 29f8dc0ca..6d0d896a1 100644 --- a/source/core/slang-string-util.cpp +++ b/source/core/slang-string-util.cpp @@ -2,6 +2,19 @@ namespace Slang { +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! StringBlob !!!!!!!!!!!!!!!!!!!!!!!!!!! + +// Allocate static const storage for the various interface IDs that the Slang API needs to expose +static const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown; +static const Guid IID_ISlangBlob = SLANG_UUID_ISlangBlob; + +/* static */ISlangUnknown* StringBlob::getInterface(const Guid& guid) +{ + return (guid == IID_ISlangUnknown || guid == IID_ISlangBlob) ? static_cast<ISlangBlob*>(this) : nullptr; +} + +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! StringUtil !!!!!!!!!!!!!!!!!!!!!!!!!!! + /* static */void StringUtil::split(const UnownedStringSlice& in, char splitChar, List<UnownedStringSlice>& slicesOut) { slicesOut.Clear(); @@ -74,4 +87,28 @@ namespace Slang { return builder; } +/* static */String StringUtil::getString(ISlangBlob* blob) +{ + if (blob) + { + size_t size = blob->getBufferSize(); + if (size > 0) + { + const char* contents = (const char*)blob->getBufferPointer(); + // Check it has terminating 0, if not we must construct as if it does + if (contents[size - 1] == 0) + { + size--; + } + return String(contents, contents + size); + } + } + return String(); +} + +ComPtr<ISlangBlob> StringUtil::createStringBlob(const String& string) +{ + return ComPtr<ISlangBlob>(new StringBlob(string)); +} + } // namespace Slang diff --git a/source/core/slang-string-util.h b/source/core/slang-string-util.h index fc3258490..47d92f2fe 100644 --- a/source/core/slang-string-util.h +++ b/source/core/slang-string-util.h @@ -6,8 +6,41 @@ #include <stdarg.h> +#include "../../slang-com-helper.h" +#include "../../slang-com-ptr.h" + namespace Slang { +/** A blob that uses a `String` for its storage. +*/ +class StringBlob : public ISlangBlob +{ +public: + // ISlangUnknown + SLANG_IUNKNOWN_ALL + + // ISlangBlob + SLANG_NO_THROW void const* SLANG_MCALL getBufferPointer() SLANG_OVERRIDE { return m_string.Buffer(); } + SLANG_NO_THROW size_t SLANG_MCALL getBufferSize() SLANG_OVERRIDE { return m_string.Length(); } + + /// Get the contained string + SLANG_FORCE_INLINE const String& getString() const { return m_string; } + + explicit StringBlob(String const& string) + : m_string(string) + {} + + /// Need virtual dtor, because BlobBase is derived from and release impl used is the one in the base class (that doesn't know the derived type) + /// Alternatively could be implemented by always using SLANG_IUNKNOWN_RELEASE in derived types - this would make derived types slightly smaller/faster + virtual ~StringBlob() {} + +protected: + ISlangUnknown* getInterface(const Guid& guid); + + String m_string; + uint32_t m_refCount = 0; +}; + struct StringUtil { /// Split in, by specified splitChar into slices out @@ -22,6 +55,14 @@ struct StringUtil /// Create a string from the format string applying args (like sprintf) static String makeStringWithFormat(const char* format, ...); + + /// Given a string held in a blob, returns as a String + /// Returns an empty string if blob is nullptr + static String getString(ISlangBlob* blob); + + /// Create a blob from a string + static ComPtr<ISlangBlob> createStringBlob(const String& string); + }; } // namespace Slang diff --git a/source/slang/compiler.cpp b/source/slang/compiler.cpp index 4b7fcb554..f16ad06b7 100644 --- a/source/slang/compiler.cpp +++ b/source/slang/compiler.cpp @@ -3,6 +3,8 @@ #include "../core/basic.h" #include "../core/platform.h" #include "../core/slang-io.h" +#include "../core/slang-string-util.h" + #include "bytecode.h" #include "compiler.h" #include "lexer.h" @@ -108,7 +110,7 @@ namespace Slang break; case ResultFormat::Text: - blob = createStringBlob(outputString); + blob = StringUtil::createStringBlob(outputString); break; case ResultFormat::Binary: diff --git a/source/slang/compiler.h b/source/slang/compiler.h index 04508837f..de099c40b 100644 --- a/source/slang/compiler.h +++ b/source/slang/compiler.h @@ -287,9 +287,6 @@ namespace Slang class Session; - /// Create a blob that will retain a string for its lifetime. - /// - ComPtr<ISlangBlob> createStringBlob(String const& string); /// Create a blob that will retain (a copy of) raw data. /// @@ -411,8 +408,6 @@ namespace Slang CompileRequest(Session* session); - ~CompileRequest(); - RefPtr<Expr> parseTypeString(TranslationUnitRequest * translationUnit, String typeStr, RefPtr<Scope> scope); Type* getTypeFromString(String typeStr); diff --git a/source/slang/default-file-system.cpp b/source/slang/default-file-system.cpp deleted file mode 100644 index f9c66b7d7..000000000 --- a/source/slang/default-file-system.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#include "default-file-system.h" - -#include "../../slang-com-ptr.h" -#include "../core/slang-io.h" -#include "compiler.h" - -namespace Slang -{ - -// Allocate static const storage for the various interface IDs that the Slang API needs to expose -static const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown; -static const Guid IID_ISlangFileSystem = SLANG_UUID_ISlangFileSystem; -static const Guid IID_ISlangFileSystemExt = SLANG_UUID_ISlangFileSystemExt; - -/* !!!!!!!!!!!!!!!!!!!!!!!!!! IncludeFileSystem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ - -/* static */DefaultFileSystem DefaultFileSystem::s_singleton; - -ISlangUnknown* DefaultFileSystem::getInterface(const Guid& guid) -{ - return (guid == IID_ISlangUnknown || guid == IID_ISlangFileSystem || guid == IID_ISlangFileSystemExt) ? static_cast<ISlangFileSystemExt*>(this) : nullptr; -} - -SlangResult DefaultFileSystem::getCanoncialPath(const char* path, ISlangBlob** canonicalPathOut) -{ - String canonicalPath; - SLANG_RETURN_ON_FAIL(Path::GetCanonical(path, canonicalPath)); - - *canonicalPathOut = createStringBlob(canonicalPath).detach(); - return SLANG_OK; -} - -SlangResult DefaultFileSystem::calcRelativePath(SlangPathType fromPathType, const char* fromPath, const char* path, ISlangBlob** pathOut) -{ - String relPath; - switch (fromPathType) - { - case SLANG_PATH_TYPE_FILE: - { - relPath = Path::Combine(Path::GetDirectoryName(fromPath), path); - break; - } - case SLANG_PATH_TYPE_DIRECTORY: - { - relPath = Path::Combine(fromPath, path); - break; - } - } - - *pathOut = createStringBlob(relPath).detach(); - return SLANG_OK; -} - -SlangResult SLANG_MCALL DefaultFileSystem::getPathType( - const char* path, - SlangPathType* pathTypeOut) -{ - return Path::GetPathType(path, pathTypeOut); -} - -SlangResult DefaultFileSystem::loadFile(char const* path, ISlangBlob** outBlob) -{ - // Default implementation that uses the `core` libraries facilities for talking to the OS filesystem. - // - // TODO: we might want to conditionally compile these in, so that - // a user could create a build of Slang that doesn't include any OS - // filesystem calls. - - if (!File::Exists(path)) - { - return SLANG_E_NOT_FOUND; - } - - try - { - String sourceString = File::ReadAllText(path); - ComPtr<ISlangBlob> sourceBlob = createStringBlob(sourceString); - *outBlob = sourceBlob.detach(); - return SLANG_OK; - } - catch (...) - { - } - return SLANG_E_CANNOT_OPEN; -} - -/* !!!!!!!!!!!!!!!!!!!!!!!!!! WrapFileSystem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ - -ISlangUnknown* WrapFileSystem::getInterface(const Guid& guid) -{ - return (guid == IID_ISlangUnknown || guid == IID_ISlangFileSystem || guid == IID_ISlangFileSystemExt) ? static_cast<ISlangFileSystemExt*>(this) : nullptr; -} - -SlangResult WrapFileSystem::loadFile(char const* path, ISlangBlob** outBlob) -{ - // Used the wrapped file system to do the loading - return m_fileSystem->loadFile(path, outBlob); -} - -SlangResult WrapFileSystem::getCanoncialPath(const char* path, ISlangBlob** canonicalPathOut) -{ - // This isn't a very good 'canonical path' because the same file might be referenced - // multiple ways - for example by using relative paths. - // But it's simple and matches slangs previous behavior. - String canonicalPath(path); - *canonicalPathOut = createStringBlob(canonicalPath).detach(); - return SLANG_OK; -} - -SlangResult WrapFileSystem::calcRelativePath(SlangPathType fromPathType, const char* fromPath, const char* path, ISlangBlob** pathOut) -{ - // Just defer to the default implementation - return DefaultFileSystem::getSingleton()->calcRelativePath(fromPathType, fromPath, path, pathOut); -} - -SlangResult WrapFileSystem::getPathType(const char* path, SlangPathType* pathTypeOut) -{ - // TODO: - // This might be undesirable in the longer term because it means that ISlangFileSystem will not be used - // to test file existence - but the file system will be. - // - // It would probably be better to use some kind of cache that uses 'loadFile' to load files, but also - // to test for existence. - return DefaultFileSystem::getSingleton()->getPathType(path, pathTypeOut); -} - -}
\ No newline at end of file diff --git a/source/slang/default-file-system.h b/source/slang/default-file-system.h deleted file mode 100644 index 7805dd81a..000000000 --- a/source/slang/default-file-system.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef SLANG_DEFAULT_FILE_SYSTEM_H_INCLUDED -#define SLANG_DEFAULT_FILE_SYSTEM_H_INCLUDED - -#include "../../slang.h" -#include "../../slang-com-helper.h" -#include "../../slang-com-ptr.h" - -namespace Slang -{ - -class DefaultFileSystem : public ISlangFileSystemExt -{ -public: - // ISlangUnknown - // override ref counting, as DefaultFileSystem is singleton - SLANG_IUNKNOWN_QUERY_INTERFACE - SLANG_NO_THROW uint32_t SLANG_MCALL addRef() SLANG_OVERRIDE { return 1; } - SLANG_NO_THROW uint32_t SLANG_MCALL release() SLANG_OVERRIDE { return 1; } - - // ISlangFileSystem - virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadFile( - char const* path, - ISlangBlob** outBlob) SLANG_OVERRIDE; - - // ISlangFileSystemExt - virtual SLANG_NO_THROW SlangResult SLANG_MCALL getCanoncialPath( - const char* path, - ISlangBlob** canonicalPathOut) SLANG_OVERRIDE; - - virtual SLANG_NO_THROW SlangResult SLANG_MCALL calcRelativePath( - SlangPathType fromPathType, - const char* fromPath, - const char* path, - ISlangBlob** pathOut) SLANG_OVERRIDE; - - virtual SLANG_NO_THROW SlangResult SLANG_MCALL getPathType( - const char* path, - SlangPathType* pathTypeOut) SLANG_OVERRIDE; - - /// Get a default instance - static ISlangFileSystemExt* getSingleton() { return &s_singleton; } - -private: - /// Make so not constructible - DefaultFileSystem() {} - virtual ~DefaultFileSystem() {} - - ISlangUnknown* getInterface(const Guid& guid); - - static DefaultFileSystem s_singleton; -}; - -/* Wraps an ISlangFileSystem, and provides the extra methods required to make a ISlangFileSystemExt -interface, deferring to the contained file system to do reading. - -NOTE! That this behavior is the same as previously in that.... -1) calcRelativePath, just returns the path as processed by the Path:: methods -2) getCanonicalPath, just returns the input path as the 'canonical' path. This will be wrong with a file multiply referenced through paths with .. and or . but -doing it this way means it works as before and requires no new functions. -*/ -class WrapFileSystem : public ISlangFileSystemExt -{ -public: - // ISlangUnknown - SLANG_IUNKNOWN_ALL - - // ISlangFileSystem - virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadFile( - char const* path, - ISlangBlob** outBlob) SLANG_OVERRIDE; - - // ISlangFileSystemExt - virtual SLANG_NO_THROW SlangResult SLANG_MCALL getCanoncialPath( - const char* path, - ISlangBlob** canonicalPathOut) SLANG_OVERRIDE; - - virtual SLANG_NO_THROW SlangResult SLANG_MCALL calcRelativePath( - SlangPathType fromPathType, - const char* fromPath, - const char* path, - ISlangBlob** pathOut) SLANG_OVERRIDE; - - virtual SLANG_NO_THROW SlangResult SLANG_MCALL getPathType( - const char* path, - SlangPathType* pathTypeOut) SLANG_OVERRIDE; - - /// Ctor - WrapFileSystem(ISlangFileSystem* fileSystem): - m_fileSystem(fileSystem) - { - } - virtual ~WrapFileSystem() {} - - -protected: - ISlangUnknown* getInterface(const Guid& guid); - - ComPtr<ISlangFileSystem> m_fileSystem; ///< The wrapped file system - uint32_t m_refCount = 0; -}; - -} - -#endif
\ No newline at end of file diff --git a/source/slang/preprocessor.cpp b/source/slang/preprocessor.cpp index 47aa0cfd4..0bda70891 100644 --- a/source/slang/preprocessor.cpp +++ b/source/slang/preprocessor.cpp @@ -1637,7 +1637,7 @@ static void HandleIncludeDirective(PreprocessorDirectiveContext* context) if (!sourceFile) { ComPtr<ISlangBlob> foundSourceBlob; - if (SLANG_FAILED(includeHandler->readFile(filePathInfo.canonicalPath, foundSourceBlob.writeRef()))) + if (SLANG_FAILED(includeHandler->readFile(filePathInfo.foundPath, foundSourceBlob.writeRef()))) { GetSink(context)->diagnose(pathToken.loc, Diagnostics::includeFailed, path); return; diff --git a/source/slang/slang-file-system.cpp b/source/slang/slang-file-system.cpp new file mode 100644 index 000000000..ef77dbf33 --- /dev/null +++ b/source/slang/slang-file-system.cpp @@ -0,0 +1,275 @@ +#include "slang-file-system.h" + +#include "../../slang-com-ptr.h" +#include "../core/slang-io.h" +#include "../core/slang-string-util.h" + +#include "compiler.h" + +namespace Slang +{ + +// Allocate static const storage for the various interface IDs that the Slang API needs to expose +static const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown; +static const Guid IID_ISlangFileSystem = SLANG_UUID_ISlangFileSystem; +static const Guid IID_ISlangFileSystemExt = SLANG_UUID_ISlangFileSystemExt; + +// Cacluate a relative path, just using Path:: string processing +static SlangResult _calcRelativePath(SlangPathType fromPathType, const char* fromPath, const char* path, ISlangBlob** pathOut) +{ + String relPath; + switch (fromPathType) + { + case SLANG_PATH_TYPE_FILE: + { + relPath = Path::Combine(Path::GetDirectoryName(fromPath), path); + break; + } + case SLANG_PATH_TYPE_DIRECTORY: + { + relPath = Path::Combine(fromPath, path); + break; + } + } + + *pathOut = StringUtil::createStringBlob(relPath).detach(); + return SLANG_OK; +} + +/* !!!!!!!!!!!!!!!!!!!!!!!!!! IncludeFileSystem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ + +/* static */DefaultFileSystem DefaultFileSystem::s_singleton; + +template <typename T> +static ISlangFileSystemExt* _getInterface(T* ptr, const Guid& guid) +{ + return (guid == IID_ISlangUnknown || guid == IID_ISlangFileSystem || guid == IID_ISlangFileSystemExt) ? static_cast<ISlangFileSystemExt*>(ptr) : nullptr; +} + +ISlangUnknown* DefaultFileSystem::getInterface(const Guid& guid) +{ + return _getInterface(this, guid); +} + +SlangResult DefaultFileSystem::getCanoncialPath(const char* path, ISlangBlob** canonicalPathOut) +{ + String canonicalPath; + SLANG_RETURN_ON_FAIL(Path::GetCanonical(path, canonicalPath)); + + *canonicalPathOut = StringUtil::createStringBlob(canonicalPath).detach(); + return SLANG_OK; +} + +SlangResult DefaultFileSystem::calcRelativePath(SlangPathType fromPathType, const char* fromPath, const char* path, ISlangBlob** pathOut) +{ + return _calcRelativePath(fromPathType, fromPath, path, pathOut); +} + +SlangResult SLANG_MCALL DefaultFileSystem::getPathType( + const char* path, + SlangPathType* pathTypeOut) +{ + return Path::GetPathType(path, pathTypeOut); +} + +SlangResult DefaultFileSystem::loadFile(char const* path, ISlangBlob** outBlob) +{ + // Default implementation that uses the `core` libraries facilities for talking to the OS filesystem. + // + // TODO: we might want to conditionally compile these in, so that + // a user could create a build of Slang that doesn't include any OS + // filesystem calls. + + if (!File::Exists(path)) + { + return SLANG_E_NOT_FOUND; + } + + try + { + String sourceString = File::ReadAllText(path); + *outBlob = StringUtil::createStringBlob(sourceString).detach(); + return SLANG_OK; + } + catch (...) + { + } + return SLANG_E_CANNOT_OPEN; +} + +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CacheFileSystem !!!!!!!!!!!!!!!!!!!!!!!!!!! + +/* static */ const Result CacheFileSystem::s_compressedResultToResult[] = +{ + SLANG_E_UNINITIALIZED, + SLANG_OK, ///< Ok + SLANG_E_NOT_FOUND, ///< File not found + SLANG_E_CANNOT_OPEN, ///< CannotOpen, + SLANG_FAIL, ///< Fail +}; + +/* static */CacheFileSystem::CompressedResult CacheFileSystem::toCompressedResult(Result res) +{ + if (SLANG_SUCCEEDED(res)) + { + return CompressedResult::Ok; + } + switch (res) + { + case SLANG_E_CANNOT_OPEN: return CompressedResult::CannotOpen; + case SLANG_E_NOT_FOUND: return CompressedResult::NotFound; + default: return CompressedResult::Fail; + } +} + +ISlangUnknown* CacheFileSystem::getInterface(const Guid& guid) +{ + return _getInterface(this, guid); +} + +CacheFileSystem::CacheFileSystem(ISlangFileSystem* fileSystem, bool useSimplifyForCanonicalPath) : + m_fileSystem(fileSystem), + m_useSimplifyForCanonicalPath(useSimplifyForCanonicalPath) +{ + // Try to get the more sophisticated interface + fileSystem->queryInterface(IID_ISlangFileSystemExt, (void**)m_fileSystemExt.writeRef()); +} + +CacheFileSystem::~CacheFileSystem() +{ + for (const auto& pair : m_canonicalMap) + { + delete pair.Value; + } +} + +CacheFileSystem::PathInfo* CacheFileSystem::_getPathInfo(const String& relPath) +{ + PathInfo** infoPtr = m_pathMap.TryGetValue(relPath); + if (infoPtr) + { + return *infoPtr; + } + + String canonicalPath; + if (m_fileSystemExt) + { + // Try getting the canonical path + // Okay request from the underlying file system the canonical path + ComPtr<ISlangBlob> canonicalBlob; + if (SLANG_FAILED(m_fileSystemExt->getCanoncialPath(relPath.Buffer(), canonicalBlob.writeRef()))) + { + // Write in result as being null ptr so not tried again + m_pathMap.Add(relPath, nullptr); + return nullptr; + } + // Get the path as a string + canonicalPath = StringUtil::getString(canonicalBlob); + } + else + { + canonicalPath = m_useSimplifyForCanonicalPath ? Path::Simplify(relPath.getUnownedSlice()) : relPath; + } + + PathInfo* pathInfo; + infoPtr = m_canonicalMap.TryGetValue(canonicalPath); + if (infoPtr) + { + pathInfo = *infoPtr; + } + else + { + // Create and add to canonical path + pathInfo = new PathInfo(canonicalPath); + m_canonicalMap.Add(canonicalPath, pathInfo); + } + + // Add the relPath + m_pathMap.Add(relPath, pathInfo); + return pathInfo; +} + +SlangResult CacheFileSystem::loadFile(char const* pathIn, ISlangBlob** blobOut) +{ + *blobOut = nullptr; + String path(pathIn); + PathInfo* info = _getPathInfo(path); + if (!info) + { + return SLANG_FAIL; + } + + if (info->m_loadFileResult == CompressedResult::Uninitialized) + { + info->m_loadFileResult = toCompressedResult(m_fileSystem->loadFile(path.Buffer(), info->m_fileBlob.writeRef())); + } + + *blobOut = info->m_fileBlob; + if (*blobOut) + { + (*blobOut)->addRef(); + } + return toResult(info->m_loadFileResult); +} + +SlangResult CacheFileSystem::getCanoncialPath(const char* path, ISlangBlob** canonicalPathOut) +{ + PathInfo* info = _getPathInfo(path); + if (!info) + { + return SLANG_E_NOT_FOUND; + } + info->m_canonicalPath->addRef(); + *canonicalPathOut = info->m_canonicalPath; + return SLANG_OK; +} + +SlangResult CacheFileSystem::calcRelativePath(SlangPathType fromPathType, const char* fromPath, const char* path, ISlangBlob** pathOut) +{ + // Just defer to contained implementation + if (m_fileSystemExt) + { + return m_fileSystemExt->calcRelativePath(fromPathType, fromPath, path, pathOut); + } + else + { + // Just use the default implementation + return _calcRelativePath(fromPathType, fromPath, path, pathOut); + } +} + +SlangResult CacheFileSystem::getPathType(const char* pathIn, SlangPathType* pathTypeOut) +{ + String path(pathIn); + PathInfo* info = _getPathInfo(path); + if (!info) + { + return SLANG_E_NOT_FOUND; + } + + if (info->m_getPathTypeResult == CompressedResult::Uninitialized) + { + if (m_fileSystemExt) + { + info->m_getPathTypeResult = toCompressedResult(m_fileSystemExt->getPathType(pathIn, &info->m_pathType)); + } + else + { + // Okay try to load the file + if (info->m_loadFileResult == CompressedResult::Uninitialized) + { + info->m_loadFileResult = toCompressedResult(m_fileSystem->loadFile(path.Buffer(), info->m_fileBlob.writeRef())); + } + + // Make the getPathResult the same as the load result + info->m_getPathTypeResult = info->m_loadFileResult; + // Just set to file... the result is what matters in this case + info->m_pathType = SLANG_PATH_TYPE_FILE; + } + } + + *pathTypeOut = info->m_pathType; + return toResult(info->m_getPathTypeResult); +} + +}
\ No newline at end of file diff --git a/source/slang/slang-file-system.h b/source/slang/slang-file-system.h new file mode 100644 index 000000000..c1358654a --- /dev/null +++ b/source/slang/slang-file-system.h @@ -0,0 +1,161 @@ +#ifndef SLANG_FILE_SYSTEM_H_INCLUDED +#define SLANG_FILE_SYSTEM_H_INCLUDED + +#include "../../slang.h" +#include "../../slang-com-helper.h" +#include "../../slang-com-ptr.h" + +#include "../core/slang-string-util.h" +#include "../core/dictionary.h" + +namespace Slang +{ + +class DefaultFileSystem : public ISlangFileSystemExt +{ +public: + // ISlangUnknown + // override ref counting, as DefaultFileSystem is singleton + SLANG_IUNKNOWN_QUERY_INTERFACE + SLANG_NO_THROW uint32_t SLANG_MCALL addRef() SLANG_OVERRIDE { return 1; } + SLANG_NO_THROW uint32_t SLANG_MCALL release() SLANG_OVERRIDE { return 1; } + + // ISlangFileSystem + virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadFile( + char const* path, + ISlangBlob** outBlob) SLANG_OVERRIDE; + + // ISlangFileSystemExt + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getCanoncialPath( + const char* path, + ISlangBlob** canonicalPathOut) SLANG_OVERRIDE; + + virtual SLANG_NO_THROW SlangResult SLANG_MCALL calcRelativePath( + SlangPathType fromPathType, + const char* fromPath, + const char* path, + ISlangBlob** pathOut) SLANG_OVERRIDE; + + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getPathType( + const char* path, + SlangPathType* pathTypeOut) SLANG_OVERRIDE; + + /// Get a default instance + static ISlangFileSystemExt* getSingleton() { return &s_singleton; } + +private: + /// Make so not constructible + DefaultFileSystem() {} + virtual ~DefaultFileSystem() {} + + ISlangUnknown* getInterface(const Guid& guid); + + static DefaultFileSystem s_singleton; +}; + +/* Wraps an underlying ISlangFileSystem or ISlangFileSystemExt and provides caching, +as well as emulation of methods if only has ISlangFileSystem interface. Will query capabilities +of the interface on the constructor. + +NOTE! That this behavior is the same as previously in that.... +1) calcRelativePath, just returns the path as processed by the Path:: methods +2) getCanonicalPath, just returns the input path as the 'canonical' path. This will be wrong with a file multiply referenced through paths with .. and or . but +doing it this way means it works as before and requires no new functions. + +You can use a more sophisticated canonical style if you pass true to useSimplifyForCanonicalPath. This will simplify relative path to create a canonical path. +*/ +class CacheFileSystem: public ISlangFileSystemExt +{ + public: + + /* Cannot change order/add members without changing s_compressedResultToResult */ + enum class CompressedResult: uint8_t + { + Uninitialized, ///< Holds no value + Ok, ///< Ok + NotFound, ///< File not found + CannotOpen, ///< Cannot open + Fail, ///< Generic failure + CountOf, + }; + + // ISlangUnknown + SLANG_IUNKNOWN_ALL + + // ISlangFileSystem + virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadFile( + char const* path, + ISlangBlob** outBlob) SLANG_OVERRIDE; + + // ISlangFileSystemExt + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getCanoncialPath( + const char* path, + ISlangBlob** canonicalPathOut) SLANG_OVERRIDE; + + virtual SLANG_NO_THROW SlangResult SLANG_MCALL calcRelativePath( + SlangPathType fromPathType, + const char* fromPath, + const char* path, + ISlangBlob** pathOut) SLANG_OVERRIDE; + + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getPathType( + const char* path, + SlangPathType* pathTypeOut) SLANG_OVERRIDE; + + /// Ctor + CacheFileSystem(ISlangFileSystem* fileSystem, bool useSimplifyForCanonicalPath = false); + /// Dtor + ~CacheFileSystem(); + + static CompressedResult toCompressedResult(Result res); + static Result toResult(CompressedResult compRes) { return s_compressedResultToResult[int(compRes)]; } + static const Result s_compressedResultToResult[int(CompressedResult::CountOf)]; + +protected: + ISlangUnknown* getInterface(const Guid& guid); + + struct PathInfo + { + PathInfo(const String& canonicalPath) + { + m_canonicalPath = new StringBlob(canonicalPath); + m_canonicalPath->addRef(); + + m_loadFileResult = CompressedResult::Uninitialized; + m_getPathTypeResult = CompressedResult::Uninitialized; + } + ~PathInfo() + { + m_canonicalPath->release(); + } + /// Get the canonical path as a string + const String& getCanonicalPath() const { SLANG_ASSERT(m_canonicalPath); return m_canonicalPath->getString(); } + + StringBlob* m_canonicalPath; ///< The canonical path + CompressedResult m_loadFileResult; + CompressedResult m_getPathTypeResult; + SlangPathType m_pathType; + ComPtr<ISlangBlob> m_fileBlob; + }; + + /// For a given relPath gets a PathInfo + PathInfo* _getPathInfo(const String& relPath); + + /* TODO: This may be improved by mapping to a ISlangBlob. This makes output fast and easy, and if constructed + as a StringBlob, we can just static_cast to get as a string to use internally, instead of constantly converting. + It is probably the case we cannot do dynamic_cast on ISlangBlob if we don't know where constructed -> if outside of slang codebase + doing such a cast can cause an exception. So we *never* want to do dynamic cast from blobs which could be created by external code. */ + + Dictionary<String, PathInfo*> m_pathMap; ///< Maps a path to a canonical path + Dictionary<String, PathInfo*> m_canonicalMap; ///< Maps a canonical path to a files contents. This OWNs the PathInfo. + + bool m_useSimplifyForCanonicalPath; ///< If set will use Path::Simplify to create 'canonical' paths + + ComPtr<ISlangFileSystem> m_fileSystem; ///< Must always be set + ComPtr<ISlangFileSystemExt> m_fileSystemExt; ///< Optionally set -> if not will fall back on the m_fileSystem + uint32_t m_refCount = 0; +}; + +} + +#endif // SLANG_FILE_SYSTEM_H_INCLUDED
\ No newline at end of file diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 996f8e32f..38fe88ef3 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -1,6 +1,8 @@ #include "../../slang.h" #include "../core/slang-io.h" +#include "../core/slang-string-util.h" + #include "parameter-binding.h" #include "lower-to-ir.h" #include "../slang/parser.h" @@ -9,7 +11,7 @@ #include "syntax-visitors.h" #include "../slang/type-layout.h" -#include "default-file-system.h" +#include "slang-file-system.h" #include "ir-serialize.h" @@ -77,25 +79,6 @@ Session::Session() addBuiltinSource(hlslLanguageScope, "hlsl", getHLSLLibraryCode()); } -static String getString(ISlangBlob* blob) -{ - if (blob) - { - size_t size = blob->getBufferSize(); - if (size > 0) - { - const char* contents = (const char*)blob->getBufferPointer(); - // Check it has terminating 0, if not we must construct as if it does - if (contents[size - 1] == 0) - { - size --; - } - return String(contents, contents + size); - } - } - return String(); -} - struct IncludeHandlerImpl : IncludeHandler { CompileRequest* request; @@ -112,7 +95,7 @@ struct IncludeHandlerImpl : IncludeHandler // Get relative path ComPtr<ISlangBlob> relPathBlob; SLANG_RETURN_ON_FAIL(fileSystemExt->calcRelativePath(fromPathType, fromPath.begin(), path.begin(), relPathBlob.writeRef())); - String relPath(getString(relPathBlob)); + String relPath(StringUtil::getString(relPathBlob)); if (relPath.Length() <= 0) { return SLANG_FAIL; @@ -130,7 +113,7 @@ struct IncludeHandlerImpl : IncludeHandler SLANG_RETURN_ON_FAIL(fileSystemExt->getCanoncialPath(relPath.begin(), canonicalPathBlob.writeRef())); // If the rel path exists -> the canonical path MUST exists too - String canonicalPath(getString(canonicalPathBlob)); + String canonicalPath(StringUtil::getString(canonicalPathBlob)); if (canonicalPath.Length() <= 0) { // Canonical path can't be empty @@ -323,16 +306,7 @@ CompileRequest::CompileRequest(Session* session) // Set up the default file system SLANG_ASSERT(fileSystem == nullptr); - fileSystemExt = DefaultFileSystem::getSingleton(); -} - -CompileRequest::~CompileRequest() -{ - // delete things that may reference IR objects first - targets = decltype(targets)(); - translationUnits = decltype(translationUnits)(); - entryPoints = decltype(entryPoints)(); - types = decltype(types)(); + fileSystemExt = new CacheFileSystem(DefaultFileSystem::getSingleton()); } // Allocate static const storage for the various interface IDs that the Slang API needs to expose @@ -360,27 +334,6 @@ protected: } }; -/** A blob that uses a `String` for its storage. -*/ -class StringBlob : public BlobBase -{ -public: - // ISlangBlob - SLANG_NO_THROW void const* SLANG_MCALL getBufferPointer() SLANG_OVERRIDE { return m_string.Buffer(); } - SLANG_NO_THROW size_t SLANG_MCALL getBufferSize() SLANG_OVERRIDE { return m_string.Length(); } - - explicit StringBlob(String const& string) - : m_string(string) - {} -protected: - String m_string; -}; - -ComPtr<ISlangBlob> createStringBlob(String const& string) -{ - return ComPtr<ISlangBlob>(new StringBlob(string)); -} - /** A blob that manages some raw data that it owns. */ class RawBlob : public BlobBase @@ -972,7 +925,7 @@ RefPtr<ModuleDecl> CompileRequest::findOrImportModule( PathInfo pathIncludedFromInfo = getSourceManager()->getPathInfo(loc, SourceLocType::Actual); PathInfo filePathInfo; - // There is an argument to passing in the 'canonicalPath' instead of the foundPath, but either should work here + // We are going to allow canonicalPath to be able to hold strings other than paths (like hashes), therefore we have to load via the found path if (SLANG_FAILED(includeHandler.findFile(fileName, pathIncludedFromInfo.foundPath, filePathInfo))) { this->mSink.diagnose(loc, Diagnostics::cannotFindFile, fileName); @@ -981,12 +934,12 @@ RefPtr<ModuleDecl> CompileRequest::findOrImportModule( } // Maybe this was loaded previously at a different relative name? - if (mapPathToLoadedModule.TryGetValue(filePathInfo.canonicalPath, loadedModule)) + if (mapPathToLoadedModule.TryGetValue(filePathInfo.getMostUniquePath(), loadedModule)) return loadedModule->moduleDecl; // Try to load it ComPtr<ISlangBlob> fileContents; - if (SLANG_FAILED(includeHandler.readFile(filePathInfo.canonicalPath, fileContents.writeRef()))) + if (SLANG_FAILED(includeHandler.readFile(filePathInfo.foundPath, fileContents.writeRef()))) { this->mSink.diagnose(loc, Diagnostics::cannotOpenFile, fileName); mapNameToLoadedModules[name] = nullptr; @@ -1188,7 +1141,7 @@ SLANG_API void spSetFileSystem( // Set up fileSystemExt appropriately if (fileSystem == nullptr) { - req->fileSystemExt = Slang::DefaultFileSystem::getSingleton(); + req->fileSystemExt = new Slang::CacheFileSystem(Slang::DefaultFileSystem::getSingleton()); } else { @@ -1199,7 +1152,7 @@ SLANG_API void spSetFileSystem( if (!req->fileSystemExt) { // Construct a wrapper to emulate the extended interface behavior - req->fileSystemExt = new Slang::WrapFileSystem(fileSystem); + req->fileSystemExt = new Slang::CacheFileSystem(fileSystem); } } } @@ -1342,7 +1295,7 @@ SLANG_API SlangResult spGetDiagnosticOutputBlob( if(!req->diagnosticOutputBlob) { - req->diagnosticOutputBlob = Slang::createStringBlob(req->mDiagnosticOutput); + req->diagnosticOutputBlob = Slang::StringUtil::createStringBlob(req->mDiagnosticOutput); } Slang::ComPtr<ISlangBlob> resultBlob = req->diagnosticOutputBlob; diff --git a/source/slang/slang.vcxproj b/source/slang/slang.vcxproj index b899506b4..6bcaac3da 100644 --- a/source/slang/slang.vcxproj +++ b/source/slang/slang.vcxproj @@ -175,7 +175,6 @@ <ClInclude Include="compiler.h" /> <ClInclude Include="core.meta.slang.h" /> <ClInclude Include="decl-defs.h" /> - <ClInclude Include="default-file-system.h" /> <ClInclude Include="diagnostic-defs.h" /> <ClInclude Include="diagnostics.h" /> <ClInclude Include="emit.h" /> @@ -209,6 +208,7 @@ <ClInclude Include="profile-defs.h" /> <ClInclude Include="profile.h" /> <ClInclude Include="reflection.h" /> + <ClInclude Include="slang-file-system.h" /> <ClInclude Include="source-loc.h" /> <ClInclude Include="stmt-defs.h" /> <ClInclude Include="syntax-base-defs.h" /> @@ -228,7 +228,6 @@ <ClCompile Include="bytecode.cpp" /> <ClCompile Include="check.cpp" /> <ClCompile Include="compiler.cpp" /> - <ClCompile Include="default-file-system.cpp" /> <ClCompile Include="diagnostics.cpp" /> <ClCompile Include="dxc-support.cpp" /> <ClCompile Include="emit.cpp" /> @@ -255,6 +254,7 @@ <ClCompile Include="preprocessor.cpp" /> <ClCompile Include="profile.cpp" /> <ClCompile Include="reflection.cpp" /> + <ClCompile Include="slang-file-system.cpp" /> <ClCompile Include="slang-stdlib.cpp" /> <ClCompile Include="slang.cpp" /> <ClCompile Include="source-loc.cpp" /> @@ -265,13 +265,16 @@ <ClCompile Include="vm.cpp" /> </ItemGroup> <ItemGroup> + <None Include="slang.natvis" /> + </ItemGroup> + <ItemGroup> <CustomBuild Include="core.meta.slang"> <FileType>Document</FileType> <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"../../bin/windows-x86/debug/slang-generate" %(Identity)</Command> <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"../../bin/windows-x64/debug/slang-generate" %(Identity)</Command> <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"../../bin/windows-x86/release/slang-generate" %(Identity)</Command> <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"../../bin/windows-x64/release/slang-generate" %(Identity)</Command> - <Outputs>../../core.meta.slang.h</Outputs> + <Outputs>%(Identity).h</Outputs> <Message>slang-generate %(Identity)</Message> <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../bin/windows-x86/debug/slang-generate.exe</AdditionalInputs> <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">../../bin/windows-x64/debug/slang-generate.exe</AdditionalInputs> @@ -284,7 +287,7 @@ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"../../bin/windows-x64/debug/slang-generate" %(Identity)</Command> <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"../../bin/windows-x86/release/slang-generate" %(Identity)</Command> <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"../../bin/windows-x64/release/slang-generate" %(Identity)</Command> - <Outputs>../../hlsl.meta.slang.h</Outputs> + <Outputs>%(Identity).h</Outputs> <Message>slang-generate %(Identity)</Message> <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../bin/windows-x86/debug/slang-generate.exe</AdditionalInputs> <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">../../bin/windows-x64/debug/slang-generate.exe</AdditionalInputs> @@ -293,9 +296,6 @@ </CustomBuild> </ItemGroup> <ItemGroup> - <Natvis Include="slang.natvis" /> - </ItemGroup> - <ItemGroup> <ProjectReference Include="..\core\core.vcxproj"> <Project>{F9BE7957-8399-899E-0C49-E714FDDD4B65}</Project> </ProjectReference> diff --git a/source/slang/slang.vcxproj.filters b/source/slang/slang.vcxproj.filters index 6b51e16c8..ce76ec77e 100644 --- a/source/slang/slang.vcxproj.filters +++ b/source/slang/slang.vcxproj.filters @@ -24,9 +24,6 @@ <ClInclude Include="decl-defs.h"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="default-file-system.h"> - <Filter>Header Files</Filter> - </ClInclude> <ClInclude Include="diagnostic-defs.h"> <Filter>Header Files</Filter> </ClInclude> @@ -126,6 +123,9 @@ <ClInclude Include="reflection.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="slang-file-system.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="source-loc.h"> <Filter>Header Files</Filter> </ClInclude> @@ -179,9 +179,6 @@ <ClCompile Include="compiler.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="default-file-system.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="diagnostics.cpp"> <Filter>Source Files</Filter> </ClCompile> @@ -260,6 +257,9 @@ <ClCompile Include="reflection.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="slang-file-system.cpp"> + <Filter>Source Files</Filter> + </ClCompile> <ClCompile Include="slang-stdlib.cpp"> <Filter>Source Files</Filter> </ClCompile> @@ -286,6 +286,11 @@ </ClCompile> </ItemGroup> <ItemGroup> + <None Include="slang.natvis"> + <Filter>Source Files</Filter> + </None> + </ItemGroup> + <ItemGroup> <CustomBuild Include="core.meta.slang"> <Filter>Source Files</Filter> </CustomBuild> @@ -293,9 +298,4 @@ <Filter>Source Files</Filter> </CustomBuild> </ItemGroup> - <ItemGroup> - <Natvis Include="slang.natvis"> - <Filter>Source Files</Filter> - </Natvis> - </ItemGroup> </Project>
\ No newline at end of file diff --git a/source/slang/source-loc.cpp b/source/slang/source-loc.cpp index 1c3b8c70a..62926aa8c 100644 --- a/source/slang/source-loc.cpp +++ b/source/slang/source-loc.cpp @@ -3,6 +3,8 @@ #include "compiler.h" +#include "../core/slang-string-util.h" + namespace Slang { /* !!!!!!!!!!!!!!!!!!!!!!!!! SourceView !!!!!!!!!!!!!!!!!!!!!!!!!!!! */ @@ -323,7 +325,7 @@ SourceFile* SourceManager::createSourceFile(const PathInfo& pathInfo, ISlangBlob SourceFile* SourceManager::createSourceFile(const PathInfo& pathInfo, const String& content) { - ComPtr<ISlangBlob> contentBlob = createStringBlob(content); + ComPtr<ISlangBlob> contentBlob = StringUtil::createStringBlob(content); return createSourceFile(pathInfo, contentBlob); } diff --git a/tests/front-end/import-subdir-search-path.slang b/tests/front-end/import-subdir-search-path.slang index e58736e8f..9b7c7a520 100644 --- a/tests/front-end/import-subdir-search-path.slang +++ b/tests/front-end/import-subdir-search-path.slang @@ -4,4 +4,7 @@ __import import_subdir_a; +// Should realize it's the same thing +__import subdir.import_subdir_a; + float bar(float x) { return foo(x); }
\ No newline at end of file diff --git a/tools/slang-test/unit-test-path.cpp b/tools/slang-test/unit-test-path.cpp index ddaa39d6d..e9cfbe2e3 100644 --- a/tools/slang-test/unit-test-path.cpp +++ b/tools/slang-test/unit-test-path.cpp @@ -21,6 +21,21 @@ static void pathUnitTest() String parentPath2 = Path::GetDirectoryName(path); SLANG_CHECK(parentPath == parentPath2); } + // Test the paths + { + SLANG_CHECK(Path::Simplify(".") == "."); + SLANG_CHECK(Path::Simplify("..") == ".."); + SLANG_CHECK(Path::Simplify("blah/..") == "."); + + SLANG_CHECK(Path::Simplify("blah/.././a") == "a"); + + SLANG_CHECK(Path::Simplify("a:/what/.././../is/./../this/.") == "a:/../this"); + + SLANG_CHECK(Path::Simplify("a:/what/.././../is/./../this/./") == "a:/../this"); + + SLANG_CHECK(Path::Simplify("a:\\what\\..\\.\\..\\is\\.\\..\\this\\.\\") == "a:/../this"); + + } } SLANG_UNIT_TEST("Path", pathUnitTest);
\ No newline at end of file |
