diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-10-22 08:46:12 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-22 08:46:12 -0400 |
| commit | 10e1bae34733f1cdb5abc001666b1aafa1c1f406 (patch) | |
| tree | ad9571c071b7b7c2384cdd42426851d257fc5f7b /source | |
| parent | c0943661e5441bfb996430c4f67fb4dddea9dfcf (diff) | |
Single pass C++ extraction (#1583)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Added CharUtil.
Added TypeSet to extractor.
First pass at being able to specify all headers for multiple output headers.
* Fix includes for new C++ extractor convension.
Update premake5 to use new extractor mechanisms.
* Small improvements around StringUtil.
* Split out NameConventionUtil.
* Use a 'convert' to convert between convention types.
* Fix output of build message for C++ extractor.
Improve NameConventionUtil interface.
* Improve comments.
* Fix warning on gcc.
* Fix clang warning.
* Fix some typos in NameConventionUtil.
* Small fix to premake5.lua
* Fix generated includes.
* Remove m_reflectType as no longer applicable with TypeSet.
* Fix .gitignore for slang-generated-* files.
Added getConvention to determine convention from slice.
Add versions of split and convert that infer the from convention
* Fix typo in spliting camel.
* LineWhitespace -> HorizontalWhitespace
* Improve CharUtil comments.
Diffstat (limited to 'source')
28 files changed, 492 insertions, 108 deletions
diff --git a/source/core/core.vcxproj b/source/core/core.vcxproj index 38f06b407..063d1aa0b 100644 --- a/source/core/core.vcxproj +++ b/source/core/core.vcxproj @@ -176,6 +176,7 @@ <ClInclude Include="slang-basic.h" /> <ClInclude Include="slang-blob.h" /> <ClInclude Include="slang-byte-encode-util.h" /> + <ClInclude Include="slang-char-util.h" /> <ClInclude Include="slang-common.h" /> <ClInclude Include="slang-dictionary.h" /> <ClInclude Include="slang-downstream-compiler.h" /> @@ -189,6 +190,7 @@ <ClInclude Include="slang-list.h" /> <ClInclude Include="slang-math.h" /> <ClInclude Include="slang-memory-arena.h" /> + <ClInclude Include="slang-name-convention-util.h" /> <ClInclude Include="slang-nvrtc-compiler.h" /> <ClInclude Include="slang-offset-container.h" /> <ClInclude Include="slang-platform.h" /> @@ -219,12 +221,14 @@ <ItemGroup> <ClCompile Include="slang-blob.cpp" /> <ClCompile Include="slang-byte-encode-util.cpp" /> + <ClCompile Include="slang-char-util.cpp" /> <ClCompile Include="slang-downstream-compiler.cpp" /> <ClCompile Include="slang-free-list.cpp" /> <ClCompile Include="slang-gcc-compiler-util.cpp" /> <ClCompile Include="slang-hex-dump-util.cpp" /> <ClCompile Include="slang-io.cpp" /> <ClCompile Include="slang-memory-arena.cpp" /> + <ClCompile Include="slang-name-convention-util.cpp" /> <ClCompile Include="slang-nvrtc-compiler.cpp" /> <ClCompile Include="slang-offset-container.cpp" /> <ClCompile Include="slang-platform.cpp" /> diff --git a/source/core/core.vcxproj.filters b/source/core/core.vcxproj.filters index 7514fa1c9..afae1d124 100644 --- a/source/core/core.vcxproj.filters +++ b/source/core/core.vcxproj.filters @@ -27,6 +27,9 @@ <ClInclude Include="slang-byte-encode-util.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="slang-char-util.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="slang-common.h"> <Filter>Header Files</Filter> </ClInclude> @@ -66,6 +69,9 @@ <ClInclude Include="slang-memory-arena.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="slang-name-convention-util.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="slang-nvrtc-compiler.h"> <Filter>Header Files</Filter> </ClInclude> @@ -152,6 +158,9 @@ <ClCompile Include="slang-byte-encode-util.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="slang-char-util.cpp"> + <Filter>Source Files</Filter> + </ClCompile> <ClCompile Include="slang-downstream-compiler.cpp"> <Filter>Source Files</Filter> </ClCompile> @@ -170,6 +179,9 @@ <ClCompile Include="slang-memory-arena.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="slang-name-convention-util.cpp"> + <Filter>Source Files</Filter> + </ClCompile> <ClCompile Include="slang-nvrtc-compiler.cpp"> <Filter>Source Files</Filter> </ClCompile> diff --git a/source/core/slang-char-util.cpp b/source/core/slang-char-util.cpp new file mode 100644 index 000000000..53dd98541 --- /dev/null +++ b/source/core/slang-char-util.cpp @@ -0,0 +1,48 @@ +#include "slang-char-util.h" + +namespace Slang { + +static const CharUtil::CharFlagMap _calcCharFlagsMap() +{ + typedef CharUtil::Flag Flag; + + CharUtil::CharFlagMap map; + memset(&map, 0, sizeof(map)); + + { + for (Index i = 'a'; i <= 'z'; ++i) + { + map.flags[i] |= Flag::Lower; + } + } + { + for (Index i = 'A'; i <= 'Z'; ++i) + { + map.flags[i] |= Flag::Upper; + } + } + { + for (Index i = '0'; i <= '9'; ++i) + { + map.flags[i] |= Flag::Digit | Flag::HexDigit; + } + } + { + for (Index i = 'a'; i <= 'f'; ++i) + { + map.flags[i] |= Flag::HexDigit; + map.flags[size_t(CharUtil::toUpper(char(i)))] |= Flag::HexDigit; + } + } + + { + map.flags[size_t(' ')] |= Flag::HorizontalWhitespace; + map.flags[size_t('\t')] |= Flag::HorizontalWhitespace; + } + + return map; +} + +/* static */const CharUtil::CharFlagMap CharUtil::g_charFlagMap = _calcCharFlagsMap(); + +} // namespace Slang diff --git a/source/core/slang-char-util.h b/source/core/slang-char-util.h new file mode 100644 index 000000000..810cde0b1 --- /dev/null +++ b/source/core/slang-char-util.h @@ -0,0 +1,51 @@ +#ifndef SLANG_CORE_CHAR_UTIL_H +#define SLANG_CORE_CHAR_UTIL_H + +#include "slang-string.h" + +namespace Slang { + +struct CharUtil +{ + typedef uint8_t Flags; + struct Flag + { + enum Enum : Flags + { + Upper = 0x01, ///< A-Z + Lower = 0x02, ///< a-z + Digit = 0x04, ///< 0-9 + HorizontalWhitespace = 0x08, ///< Whitespace that can appear horizontally (ie excluding CR/LF) + HexDigit = 0x10, ///< 0-9, a-f, A-F + }; + }; + + SLANG_FORCE_INLINE static bool isDigit(char c) { return c >= '0' && c <= '9'; } + SLANG_FORCE_INLINE static bool isLower(char c) { return c >= 'a' && c <= 'z'; } + SLANG_FORCE_INLINE static bool isUpper(char c) { return c >= 'A' && c <= 'Z'; } + SLANG_FORCE_INLINE static bool isHorizontalWhitespace(char c) { return c == ' ' || c == '\t'; } + + /// True if it's alpha + SLANG_FORCE_INLINE static bool isAlpha(char c) { return (getFlags(c) & (Flag::Upper | Flag::Lower)) != 0; } + + SLANG_FORCE_INLINE static bool isHexDigit(char c) { return (getFlags(c) & Flag::HexDigit) != 0; } + + /// For a given character get the associated flags + SLANG_FORCE_INLINE static Flags getFlags(char c) { return g_charFlagMap.flags[size_t(c)]; } + + /// Given a character return the lower case equivalent + SLANG_FORCE_INLINE static char toLower(char c) { return (c >= 'A' && c <= 'Z') ? (c -'A' + 'a') : c; } + /// Given a character return the upper case equivalent + SLANG_FORCE_INLINE static char toUpper(char c) { return (c >= 'a' && c <= 'z') ? (c -'a' + 'A') : c; } + + struct CharFlagMap + { + Flags flags[0x100]; + }; + + static const CharFlagMap g_charFlagMap; +}; + +} // namespace Slang + +#endif // SLANG_CHAR_UTIL_H diff --git a/source/core/slang-name-convention-util.cpp b/source/core/slang-name-convention-util.cpp new file mode 100644 index 000000000..a5acc6370 --- /dev/null +++ b/source/core/slang-name-convention-util.cpp @@ -0,0 +1,213 @@ + +#include "slang-name-convention-util.h" + +#include "slang-char-util.h" +#include "slang-string-util.h" + +namespace Slang +{ + +/* static */NameConvention NameConventionUtil::getConvention(const UnownedStringSlice& slice) +{ + for (const char c : slice) + { + switch (c) + { + case '-': return NameConvention::Kabab; + case '_': return NameConvention::Snake; + default: break; + } + } + return NameConvention::Camel; +} + +/* static */void NameConventionUtil::split(NameConvention convention, const UnownedStringSlice& slice, List<UnownedStringSlice>& out) +{ + switch (convention) + { + case NameConvention::Kabab: + { + StringUtil::split(slice, '-', out); + break; + } + case NameConvention::Snake: + { + StringUtil::split(slice, '_', out); + break; + } + case NameConvention::Camel: + { + typedef CharUtil::Flags CharFlags; + typedef CharUtil::Flag CharFlag; + + CharFlags prevFlags = 0; + const char*const end = slice.end(); + + const char* start = slice.begin(); + for (const char* cur = start; cur < end; ++cur) + { + const char c = *cur; + const CharUtil::Flags flags = CharUtil::getFlags(c); + + if (flags & CharFlag::Upper) + { + if (prevFlags & CharFlag::Lower) + { + // If we go from lower to upper, we have a transition + out.add(UnownedStringSlice(start, cur)); + start = cur; + } + else if ((prevFlags & CharFlag::Upper) && cur + 1 < end) + { + // This works with capital or uncapitalized acronyms, but if we have two capitalized acronyms following each other - it can't split. + // + // For example + // "IAABBSystem" -> "IAABB", "System" + // + // If it only accepted lower case acronyms the logic could be changed such that the following could be produced + // "IAabbSystem" -> "I", "Aabb", "System" + // + // Since Slang source largely goes with upper case acronyms, we work with the heuristic here.. + + if (CharUtil::isLower(cur[1])) + { + out.add(UnownedStringSlice(start, cur)); + start = cur; + } + } + } + + prevFlags = flags; + } + + // Add any end section + if (start < end) + { + out.add(UnownedStringSlice(start, end)); + } + break; + } + } +} + +void NameConventionUtil::split(const UnownedStringSlice& slice, List<UnownedStringSlice>& out) +{ + split(getConvention(slice), slice, out); +} + +/* static */void NameConventionUtil::join(const UnownedStringSlice* slices, Index slicesCount, CharCase charCase, char joinChar, StringBuilder& out) +{ + if (slicesCount <= 0) + { + return; + } + + Index totalSize = slicesCount - 1; + for (Index i = 0; i < slicesCount; ++i) + { + totalSize += slices[i].getLength(); + } + + char*const dstStart = out.prepareForAppend(totalSize); + char* dst = dstStart; + + for (Index i = 0; i < slicesCount; ++i) + { + const UnownedStringSlice& slice = slices[i]; + const Index count = slice.getLength(); + const char*const src = slice.begin(); + + if (i > 0) + { + *dst++ = joinChar; + } + + switch (charCase) + { + case CharCase::Upper: + { + for (Index j = 0; j < count; ++j) + { + dst[j] = CharUtil::toUpper(src[j]); + } + break; + } + case CharCase::Lower: + { + for (Index j = 0; j < count; ++j) + { + dst[j] = CharUtil::toLower(src[j]); + } + break; + } + } + + dst += count; + } + + SLANG_ASSERT(dstStart + totalSize == dst); + out.appendInPlace(dstStart, totalSize); +} + +/* static */void NameConventionUtil::join(const UnownedStringSlice* slices, Index slicesCount, CharCase charCase, NameConvention convention, StringBuilder& out) +{ + switch (convention) + { + case NameConvention::Kabab: return join(slices, slicesCount, charCase, '-', out); + case NameConvention::Snake: return join(slices, slicesCount, charCase, '_', out); + case NameConvention::Camel: + { + Index totalSize = 0; + + for (Index i = 0; i < slicesCount; ++i) + { + totalSize += slices[i].getLength(); + } + + char*const dstStart = out.prepareForAppend(totalSize); + char* dst = dstStart; + + for (Index i = 0; i < slicesCount; ++i) + { + const UnownedStringSlice& slice = slices[i]; + Index count = slice.getLength(); + const char* src = slice.begin(); + + Int j = 0; + + if (count > 0 && !(i == 0 && charCase == CharCase::Lower)) + { + // Capitalize first letter of each word, unless on first word and 'lower' + dst[j] = CharUtil::toUpper(src[j]); + j++; + } + + for (; j < count; ++j) + { + dst[j] = CharUtil::toLower(src[j]); + } + + dst += count; + } + break; + } + } +} + +/* static */void NameConventionUtil::convert(NameConvention fromConvention, const UnownedStringSlice& slice, CharCase charCase, NameConvention toConvention, StringBuilder& out) +{ + // Split into slices + List<UnownedStringSlice> slices; + split(fromConvention, slice, slices); + + // Join the slices in the toConvention + join(slices.getBuffer(), slices.getCount(), charCase, toConvention, out); +} + +/* static */void NameConventionUtil::convert(const UnownedStringSlice& slice, CharCase charCase, NameConvention toConvention, StringBuilder& out) +{ + convert(getConvention(slice), slice, charCase, toConvention, out); +} + +} + diff --git a/source/core/slang-name-convention-util.h b/source/core/slang-name-convention-util.h new file mode 100644 index 000000000..d4a984ca0 --- /dev/null +++ b/source/core/slang-name-convention-util.h @@ -0,0 +1,54 @@ +#ifndef SLANG_CORE_NAME_CONVENTION_UTIL_H +#define SLANG_CORE_NAME_CONVENTION_UTIL_H + +#include "slang-string.h" +#include "slang-list.h" + +namespace Slang +{ + +enum class NameConvention +{ + Kabab, /// Words are separated with -. WORDS-ARE-SEPARATED + Snake, /// Words are separated with _. WORDS_ARE_SEPARATED + Camel, /// Words start with a capital. (Upper will make first words character capitalized, aka PascalCase) +}; + +enum class CharCase +{ + Upper, + Lower, +}; + +/* This utility is to enable easy conversion and interpretation of names that use standard conventions, typically in programming +languages. The conventions are largely how to represent multiple words together. + +Split is used to split up a name into it's constituent 'words' based on a convention. +Join is used to combine words based on a convention/character case + +Convert uses split and join to allow easy conversion between conventions. +*/ +struct NameConventionUtil +{ + /// Given a slice tries to determine the convention used. + /// If no separators are found, will assume Camel + static NameConvention getConvention(const UnownedStringSlice& slice); + + /// Given a slice and a naming convention, split into it's constituent parts. If convention isn't specified, will infer from slice using getConvention. + static void split(NameConvention convention, const UnownedStringSlice& slice, List<UnownedStringSlice>& out); + static void split(const UnownedStringSlice& slice, List<UnownedStringSlice>& out); + + /// Given slices, join together with the specified convention into out + static void join(const UnownedStringSlice* slices, Index slicesCount, CharCase charCase, NameConvention convention, StringBuilder& out); + + /// Join with a join char, and potentially changing case of input slices + static void join(const UnownedStringSlice* slices, Index slicesCount, CharCase charCase, char joinChar, StringBuilder& out); + + /// Convert from one convention to another. If fromConvention isn't specified, will infer from slice using getConvention. + static void convert(NameConvention fromConvention, const UnownedStringSlice& slice, CharCase charCase, NameConvention toConvention, StringBuilder& out); + static void convert(const UnownedStringSlice& slice, CharCase charCase, NameConvention toConvention, StringBuilder& out); +}; + +} + +#endif // SLANG_CORE_NAME_CONVENTION_UTIL_H diff --git a/source/core/slang-string-util.h b/source/core/slang-string-util.h index 9f1508cb1..dee4c7d66 100644 --- a/source/core/slang-string-util.h +++ b/source/core/slang-string-util.h @@ -93,6 +93,7 @@ struct StringUtil /// Convert in to int. Returns SLANG_FAIL on error static SlangResult parseInt(const UnownedStringSlice& in, Int& outValue); + }; /* A helper class that allows parsing of lines from text with iteration. Uses StringUtil::extractLine for the actual underlying implementation. */ diff --git a/source/core/slang-string.cpp b/source/core/slang-string.cpp index bcf5853d5..3ce4c7ec9 100644 --- a/source/core/slang-string.cpp +++ b/source/core/slang-string.cpp @@ -1,6 +1,8 @@ #include "slang-string.h" #include "slang-text-io.h" +#include "slang-char-util.h" + namespace Slang { // TODO: this belongs in a different file: @@ -12,11 +14,6 @@ namespace Slang throw InternalError(message); } - SLANG_FORCE_INLINE static bool _isWhiteSpace(char c) - { - return c == ' ' || c == '\t'; - } - // OSString OSString::OSString() @@ -112,11 +109,20 @@ namespace Slang const char* start = m_begin; const char* end = m_end; - while (start < end && _isWhiteSpace(*start)) start++; - while (end > start && _isWhiteSpace(end[-1])) end--; + while (start < end && CharUtil::isHorizontalWhitespace(*start)) start++; + while (end > start && CharUtil::isHorizontalWhitespace(end[-1])) end--; return UnownedStringSlice(start, end); } + UnownedStringSlice UnownedStringSlice::trim(char c) const + { + const char* start = m_begin; + const char* end = m_end; + + while (start < end && *start == c) start++; + while (end > start && end[-1] == c) end--; + return UnownedStringSlice(start, end); + } // StringSlice diff --git a/source/core/slang-string.h b/source/core/slang-string.h index 25bf99023..75c282a58 100644 --- a/source/core/slang-string.h +++ b/source/core/slang-string.h @@ -174,6 +174,7 @@ namespace Slang UnownedStringSlice trim() const; + UnownedStringSlice trim(char c) const; HashCode getHashCode() const { diff --git a/source/slang/run-generators.vcxproj b/source/slang/run-generators.vcxproj index 599f221b1..e38f9dc2d 100644 --- a/source/slang/run-generators.vcxproj +++ b/source/slang/run-generators.vcxproj @@ -156,7 +156,6 @@ <ItemGroup> <ClInclude Include="..\..\prelude\slang-cpp-scalar-intrinsics.h" /> <ClInclude Include="..\..\prelude\slang-cpp-types.h" /> - <ClInclude Include="slang-ref-object-reflect.h" /> </ItemGroup> <ItemGroup> <ClCompile Include="..\core\slang-string.cpp" /> @@ -229,24 +228,16 @@ </CustomBuild> <CustomBuild Include="slang-ast-reflect.h"> <FileType>Document</FileType> - <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"../../bin/windows-x86/debug/slang-cpp-extractor" -d %(RootDir)%(Directory) slang-ast-support-types.h -strip-prefix slang- -reflect-type Value -o slang-value-generated -output-fields -mark-suffix _VALUE_CLASS -"../../bin/windows-x86/debug/slang-cpp-extractor" -d %(RootDir)%(Directory) slang-ast-support-types.h -strip-prefix slang- -reflect-type RefObject -o slang-ref-object-generated -output-fields -mark-suffix _OBJ_CLASS -"../../bin/windows-x86/debug/slang-cpp-extractor" -d %(RootDir)%(Directory) slang-ast-base.h slang-ast-decl.h slang-ast-expr.h slang-ast-modifier.h slang-ast-stmt.h slang-ast-type.h slang-ast-val.h -strip-prefix slang-ast -reflect-type ASTNode -o slang-ast-generated -output-fields -mark-suffix _AST_CLASS</Command> - <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"../../bin/windows-x64/debug/slang-cpp-extractor" -d %(RootDir)%(Directory) slang-ast-support-types.h -strip-prefix slang- -reflect-type Value -o slang-value-generated -output-fields -mark-suffix _VALUE_CLASS -"../../bin/windows-x64/debug/slang-cpp-extractor" -d %(RootDir)%(Directory) slang-ast-support-types.h -strip-prefix slang- -reflect-type RefObject -o slang-ref-object-generated -output-fields -mark-suffix _OBJ_CLASS -"../../bin/windows-x64/debug/slang-cpp-extractor" -d %(RootDir)%(Directory) slang-ast-base.h slang-ast-decl.h slang-ast-expr.h slang-ast-modifier.h slang-ast-stmt.h slang-ast-type.h slang-ast-val.h -strip-prefix slang-ast -reflect-type ASTNode -o slang-ast-generated -output-fields -mark-suffix _AST_CLASS</Command> - <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"../../bin/windows-x86/release/slang-cpp-extractor" -d %(RootDir)%(Directory) slang-ast-support-types.h -strip-prefix slang- -reflect-type Value -o slang-value-generated -output-fields -mark-suffix _VALUE_CLASS -"../../bin/windows-x86/release/slang-cpp-extractor" -d %(RootDir)%(Directory) slang-ast-support-types.h -strip-prefix slang- -reflect-type RefObject -o slang-ref-object-generated -output-fields -mark-suffix _OBJ_CLASS -"../../bin/windows-x86/release/slang-cpp-extractor" -d %(RootDir)%(Directory) slang-ast-base.h slang-ast-decl.h slang-ast-expr.h slang-ast-modifier.h slang-ast-stmt.h slang-ast-type.h slang-ast-val.h -strip-prefix slang-ast -reflect-type ASTNode -o slang-ast-generated -output-fields -mark-suffix _AST_CLASS</Command> - <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"../../bin/windows-x64/release/slang-cpp-extractor" -d %(RootDir)%(Directory) slang-ast-support-types.h -strip-prefix slang- -reflect-type Value -o slang-value-generated -output-fields -mark-suffix _VALUE_CLASS -"../../bin/windows-x64/release/slang-cpp-extractor" -d %(RootDir)%(Directory) slang-ast-support-types.h -strip-prefix slang- -reflect-type RefObject -o slang-ref-object-generated -output-fields -mark-suffix _OBJ_CLASS -"../../bin/windows-x64/release/slang-cpp-extractor" -d %(RootDir)%(Directory) slang-ast-base.h slang-ast-decl.h slang-ast-expr.h slang-ast-modifier.h slang-ast-stmt.h slang-ast-type.h slang-ast-val.h -strip-prefix slang-ast -reflect-type ASTNode -o slang-ast-generated -output-fields -mark-suffix _AST_CLASS</Command> - <Outputs>../slangslang-value-generated.h;../slangslang-value-generated-macro.h;../slangslang-ref-object-generated.h;../slangslang-ref-object-generated-macro.h;../slangslang-ast-generated.h;../slangslang-ast-generated-macro.h</Outputs> - <Message>slang-cpp-extractor ref-object %(Identity)</Message> - <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">slang-ast-support-types.h;../../bin/windows-x86/debug/slang-cpp-extractor.exe;slang-ast-base.h;slang-ast-decl.h;slang-ast-expr.h;slang-ast-modifier.h;slang-ast-stmt.h;slang-ast-type.h;slang-ast-val.h</AdditionalInputs> - <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">slang-ast-support-types.h;../../bin/windows-x64/debug/slang-cpp-extractor.exe;slang-ast-base.h;slang-ast-decl.h;slang-ast-expr.h;slang-ast-modifier.h;slang-ast-stmt.h;slang-ast-type.h;slang-ast-val.h</AdditionalInputs> - <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">slang-ast-support-types.h;../../bin/windows-x86/release/slang-cpp-extractor.exe;slang-ast-base.h;slang-ast-decl.h;slang-ast-expr.h;slang-ast-modifier.h;slang-ast-stmt.h;slang-ast-type.h;slang-ast-val.h</AdditionalInputs> - <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">slang-ast-support-types.h;../../bin/windows-x64/release/slang-cpp-extractor.exe;slang-ast-base.h;slang-ast-decl.h;slang-ast-expr.h;slang-ast-modifier.h;slang-ast-stmt.h;slang-ast-type.h;slang-ast-val.h</AdditionalInputs> + <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"../../bin/windows-x86/debug/slang-cpp-extractor" -d %(RootDir)%(Directory) slang-ast-support-types.h slang-ast-base.h slang-ast-decl.h slang-ast-expr.h slang-ast-modifier.h slang-ast-stmt.h slang-ast-type.h slang-ast-val.h -strip-prefix slang- -o slang-generated -output-fields -mark-suffix _CLASS</Command> + <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"../../bin/windows-x64/debug/slang-cpp-extractor" -d %(RootDir)%(Directory) slang-ast-support-types.h slang-ast-base.h slang-ast-decl.h slang-ast-expr.h slang-ast-modifier.h slang-ast-stmt.h slang-ast-type.h slang-ast-val.h -strip-prefix slang- -o slang-generated -output-fields -mark-suffix _CLASS</Command> + <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"../../bin/windows-x86/release/slang-cpp-extractor" -d %(RootDir)%(Directory) slang-ast-support-types.h slang-ast-base.h slang-ast-decl.h slang-ast-expr.h slang-ast-modifier.h slang-ast-stmt.h slang-ast-type.h slang-ast-val.h -strip-prefix slang- -o slang-generated -output-fields -mark-suffix _CLASS</Command> + <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"../../bin/windows-x64/release/slang-cpp-extractor" -d %(RootDir)%(Directory) slang-ast-support-types.h slang-ast-base.h slang-ast-decl.h slang-ast-expr.h slang-ast-modifier.h slang-ast-stmt.h slang-ast-type.h slang-ast-val.h -strip-prefix slang- -o slang-generated -output-fields -mark-suffix _CLASS</Command> + <Outputs>slang-generated-obj.h;slang-generated-obj-macro.h;slang-generated-ast.h;slang-generated-ast-macro.h;slang-generated-value.h;slang-generated-value-macro.h</Outputs> + <Message>C++ Extractor %(Identity)</Message> + <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../bin/windows-x86/debug/slang-cpp-extractor.exe;slang-ast-support-types.h;slang-ast-base.h;slang-ast-decl.h;slang-ast-expr.h;slang-ast-modifier.h;slang-ast-stmt.h;slang-ast-type.h;slang-ast-val.h</AdditionalInputs> + <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">../../bin/windows-x64/debug/slang-cpp-extractor.exe;slang-ast-support-types.h;slang-ast-base.h;slang-ast-decl.h;slang-ast-expr.h;slang-ast-modifier.h;slang-ast-stmt.h;slang-ast-type.h;slang-ast-val.h</AdditionalInputs> + <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../../bin/windows-x86/release/slang-cpp-extractor.exe;slang-ast-support-types.h;slang-ast-base.h;slang-ast-decl.h;slang-ast-expr.h;slang-ast-modifier.h;slang-ast-stmt.h;slang-ast-type.h;slang-ast-val.h</AdditionalInputs> + <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">../../bin/windows-x64/release/slang-cpp-extractor.exe;slang-ast-support-types.h;slang-ast-base.h;slang-ast-decl.h;slang-ast-expr.h;slang-ast-modifier.h;slang-ast-stmt.h;slang-ast-type.h;slang-ast-val.h</AdditionalInputs> </CustomBuild> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> diff --git a/source/slang/run-generators.vcxproj.filters b/source/slang/run-generators.vcxproj.filters index 9ec19c0d7..e8ec8394a 100644 --- a/source/slang/run-generators.vcxproj.filters +++ b/source/slang/run-generators.vcxproj.filters @@ -15,9 +15,6 @@ <ClInclude Include="..\..\prelude\slang-cpp-types.h"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="slang-ref-object-reflect.h"> - <Filter>Header Files</Filter> - </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="..\core\slang-string.cpp"> diff --git a/source/slang/slang-ast-base.h b/source/slang/slang-ast-base.h index 5cbfd1e45..931f0d5bd 100644 --- a/source/slang/slang-ast-base.h +++ b/source/slang/slang-ast-base.h @@ -4,7 +4,7 @@ #include "slang-ast-support-types.h" -#include "slang-ast-generated.h" +#include "slang-generated-ast.h" #include "slang-ast-reflect.h" #include "slang-serialize-reflection.h" diff --git a/source/slang/slang-ast-decl.cpp b/source/slang/slang-ast-decl.cpp index a10411ebb..edc79c030 100644 --- a/source/slang/slang-ast-decl.cpp +++ b/source/slang/slang-ast-decl.cpp @@ -2,7 +2,7 @@ #include "slang-ast-builder.h" #include <assert.h> -#include "slang-ast-generated-macro.h" +#include "slang-generated-ast-macro.h" namespace Slang { diff --git a/source/slang/slang-ast-dump.cpp b/source/slang/slang-ast-dump.cpp index 688e99031..552c97d7f 100644 --- a/source/slang/slang-ast-dump.cpp +++ b/source/slang/slang-ast-dump.cpp @@ -6,7 +6,7 @@ #include "../core/slang-string.h" -#include "slang-ast-generated-macro.h" +#include "slang-generated-ast-macro.h" namespace Slang { diff --git a/source/slang/slang-ast-reflect.cpp b/source/slang/slang-ast-reflect.cpp index 520592e73..b16568d2e 100644 --- a/source/slang/slang-ast-reflect.cpp +++ b/source/slang/slang-ast-reflect.cpp @@ -11,7 +11,7 @@ #include "slang-visitor.h" -#include "slang-ast-generated-macro.h" +#include "slang-generated-ast-macro.h" namespace Slang { @@ -54,11 +54,11 @@ struct ASTConstructAccess #define SLANG_GET_SUPER_INNER(SUPER) &SUPER::kReflectClassInfo #define SLANG_GET_SUPER_LEAF(SUPER) &SUPER::kReflectClassInfo -#define SLANG_GET_CREATE_FUNC_ABSTRACT(NAME) nullptr -#define SLANG_GET_CREATE_FUNC_NONE(NAME) &ASTConstructAccess::Impl<NAME>::create +#define SLANG_GET_CREATE_FUNC_ABSTRACT_AST(NAME) nullptr +#define SLANG_GET_CREATE_FUNC_AST(NAME) &ASTConstructAccess::Impl<NAME>::create -#define SLANG_GET_DESTROY_FUNC_ABSTRACT(NAME) nullptr -#define SLANG_GET_DESTROY_FUNC_NONE(NAME) &ASTConstructAccess::Impl<NAME>::destroy +#define SLANG_GET_DESTROY_FUNC_ABSTRACT_AST(NAME) nullptr +#define SLANG_GET_DESTROY_FUNC_AST(NAME) &ASTConstructAccess::Impl<NAME>::destroy #define SLANG_REFLECT_CLASS_INFO(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) \ /* static */const ReflectClassInfo NAME::kReflectClassInfo = { uint32_t(ASTNodeType::NAME), uint32_t(ASTNodeType::LAST), SLANG_GET_SUPER_##TYPE(SUPER), #NAME, SLANG_GET_CREATE_FUNC_##MARKER(NAME), SLANG_GET_DESTROY_FUNC_##MARKER(NAME), uint32_t(sizeof(NAME)), uint8_t(SLANG_ALIGN_OF(NAME)) }; @@ -66,8 +66,8 @@ struct ASTConstructAccess SLANG_ALL_ASTNode_NodeBase(SLANG_REFLECT_CLASS_INFO, _) // We dispatch to non 'abstract' types -#define SLANG_CASE_NONE(NAME) case ASTNodeType::NAME: return visitor->dispatch_##NAME(static_cast<NAME*>(this), extra); -#define SLANG_CASE_ABSTRACT(NAME) +#define SLANG_CASE_AST(NAME) case ASTNodeType::NAME: return visitor->dispatch_##NAME(static_cast<NAME*>(this), extra); +#define SLANG_CASE_ABSTRACT_AST(NAME) #define SLANG_CASE_DISPATCH(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) SLANG_CASE_##MARKER(NAME) diff --git a/source/slang/slang-ast-reflect.h b/source/slang/slang-ast-reflect.h index 6ba895f71..457e88d0d 100644 --- a/source/slang/slang-ast-reflect.h +++ b/source/slang/slang-ast-reflect.h @@ -5,7 +5,7 @@ #include "slang-serialize-reflection.h" -#include "slang-ast-generated.h" +#include "slang-generated-ast.h" // Implementation for SLANG_ABSTRACT_CLASS(x) using reflection from C++ extractor in slang-ast-generated.h #define SLANG_AST_CLASS_REFLECT_IMPL(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) \ diff --git a/source/slang/slang-ast-substitutions.cpp b/source/slang/slang-ast-substitutions.cpp index 8a54a1d74..acff8201e 100644 --- a/source/slang/slang-ast-substitutions.cpp +++ b/source/slang/slang-ast-substitutions.cpp @@ -2,7 +2,7 @@ #include "slang-ast-builder.h" #include <assert.h> -#include "slang-ast-generated-macro.h" +#include "slang-generated-ast-macro.h" namespace Slang { diff --git a/source/slang/slang-ast-support-types.h b/source/slang/slang-ast-support-types.h index 4cc76804c..a2fa16b53 100644 --- a/source/slang/slang-ast-support-types.h +++ b/source/slang/slang-ast-support-types.h @@ -9,7 +9,7 @@ #include "../core/slang-semantic-version.h" -#include "slang-ast-generated.h" +#include "slang-generated-ast.h" #include "slang-serialize-reflection.h" @@ -1007,8 +1007,13 @@ namespace Slang }; class SerialRefObject; + // Make sure C++ extractor can see the base class. - SLANG_PRE_DECLARE(_OBJ_CLASS, class SerialRefObject) + SLANG_PRE_DECLARE(OBJ, class SerialRefObject) + + SLANG_TYPE_SET(OBJ, RefObject) + SLANG_TYPE_SET(VALUE, Value) + SLANG_TYPE_SET(AST, ASTNode) class LookupResultItem_Breadcrumb : public SerialRefObject { diff --git a/source/slang/slang-ast-type.cpp b/source/slang/slang-ast-type.cpp index 55bb9a1e5..2c2557233 100644 --- a/source/slang/slang-ast-type.cpp +++ b/source/slang/slang-ast-type.cpp @@ -5,7 +5,7 @@ #include "slang-syntax.h" -#include "slang-ast-generated-macro.h" +#include "slang-generated-ast-macro.h" namespace Slang { diff --git a/source/slang/slang-ast-val.cpp b/source/slang/slang-ast-val.cpp index 76ddb644c..7dbda6e86 100644 --- a/source/slang/slang-ast-val.cpp +++ b/source/slang/slang-ast-val.cpp @@ -3,7 +3,7 @@ #include <assert.h> #include <typeinfo> -#include "slang-ast-generated-macro.h" +#include "slang-generated-ast-macro.h" #include "slang-syntax.h" diff --git a/source/slang/slang-diagnostics.cpp b/source/slang/slang-diagnostics.cpp index d16e8e84e..c3b7e27a2 100644 --- a/source/slang/slang-diagnostics.cpp +++ b/source/slang/slang-diagnostics.cpp @@ -5,6 +5,8 @@ #include "../core/slang-memory-arena.h" #include "../core/slang-dictionary.h" +#include "../core/slang-string-util.h" +#include "../core/slang-name-convention-util.h" #include <assert.h> @@ -302,60 +304,17 @@ public: return singleton; } - typedef uint8_t CharFlags; - struct CharFlag - { - enum Enum : CharFlags - { - Upper = 0x1, - Lower = 0x2, - }; - }; - - static CharFlags _classifyChar(char c) - { - CharFlags flags = 0; - flags |= (c >= 'a' && c <= 'z') ? CharFlag::Lower : 0; - flags |= (c >= 'A' && c <= 'Z') ? CharFlag::Upper : 0; - return flags; - } protected: void _add(const char* name, Index index) { - m_map.Add(UnownedStringSlice(name), index); + UnownedStringSlice nameSlice(name); + m_map.Add(nameSlice, index); - // Add a dashed version + // Add a dashed version (KababCase) { m_work.Clear(); - CharFlags prevFlags = 0; - for (const char* cur = name; *cur; cur++) - { - char c = *cur; - const CharFlags flags = _classifyChar(c); - - if (flags & CharFlag::Upper) - { - if (prevFlags & CharFlag::Lower) - { - // If we go from lower to upper, insert a dash. aA -> a-a - m_work << '-'; - } - else if (prevFlags & CharFlag::Upper) - { - // Could be an acronym, if the next character is lower, we need to insert a - here - if (_classifyChar(cur[1]) & CharFlag::Lower) - { - m_work << '-'; - } - } - // Make it lower - c = c - 'A' + 'a'; - } - m_work << c; - - prevFlags = flags; - } + NameConventionUtil::convert(NameConvention::Camel, nameSlice, CharCase::Lower, NameConvention::Kabab, m_work); UnownedStringSlice dashSlice(m_arena.allocateString(m_work.getBuffer(), m_work.getLength()), m_work.getLength()); m_map.AddIfNotExists(dashSlice, index); diff --git a/source/slang/slang-ref-object-reflect.cpp b/source/slang/slang-ref-object-reflect.cpp index caf8eb6a3..f07dcbba7 100644 --- a/source/slang/slang-ref-object-reflect.cpp +++ b/source/slang/slang-ref-object-reflect.cpp @@ -2,8 +2,8 @@ #include "slang-ref-object-reflect.h" -#include "slang-ref-object-generated.h" -#include "slang-ref-object-generated-macro.h" +#include "slang-generated-obj.h" +#include "slang-generated-obj-macro.h" #include "slang-ast-support-types.h" diff --git a/source/slang/slang-ref-object-reflect.h b/source/slang/slang-ref-object-reflect.h index cf50c010a..1fda8ee69 100644 --- a/source/slang/slang-ref-object-reflect.h +++ b/source/slang/slang-ref-object-reflect.h @@ -5,7 +5,7 @@ #include "slang-serialize-reflection.h" -#include "slang-ref-object-generated.h" +#include "slang-generated-obj.h" #include "../core/slang-smart-pointer.h" diff --git a/source/slang/slang-serialize-ast.cpp b/source/slang/slang-serialize-ast.cpp index 8310c155b..0e8acc3b3 100644 --- a/source/slang/slang-serialize-ast.cpp +++ b/source/slang/slang-serialize-ast.cpp @@ -1,8 +1,8 @@ // slang-serialize-ast.cpp #include "slang-serialize-ast.h" -#include "slang-ast-generated.h" -#include "slang-ast-generated-macro.h" +#include "slang-generated-ast.h" +#include "slang-generated-ast-macro.h" #include "slang-ast-dump.h" diff --git a/source/slang/slang-serialize-reflection.h b/source/slang/slang-serialize-reflection.h index a6889f795..7eaf8543c 100644 --- a/source/slang/slang-serialize-reflection.h +++ b/source/slang/slang-serialize-reflection.h @@ -63,6 +63,8 @@ struct ReflectClassInfo #define SLANG_PRE_DECLARE(SUFFIX, DEF) +#define SLANG_TYPE_SET(SUFFIX, ...) + // Use these macros to help define Super, and making the base definition NOT have a Super definition. // For example something like... diff --git a/source/slang/slang-visitor.h b/source/slang/slang-visitor.h index 449fda917..25e0aafe4 100644 --- a/source/slang/slang-visitor.h +++ b/source/slang/slang-visitor.h @@ -7,15 +7,15 @@ #include "slang-syntax.h" -#include "slang-ast-generated-macro.h" +#include "slang-generated-ast-macro.h" namespace Slang { // Macros to generate from ast-generated-macro file the vistors // Only runs 'param' macro if the marker is NONE (ie not ABSTRACT here) -#define SLANG_CLASS_ONLY_ABSTRACT(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) -#define SLANG_CLASS_ONLY_NONE(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) param(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) +#define SLANG_CLASS_ONLY_ABSTRACT_AST(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) +#define SLANG_CLASS_ONLY_AST(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) param(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) #define SLANG_CLASS_ONLY(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) SLANG_CLASS_ONLY_##MARKER(NAME, SUPER, ORIGIN, LAST, MARKER, TYPE, param) diff --git a/source/slang/slang.vcxproj b/source/slang/slang.vcxproj index ec3066778..bb4293b8f 100644 --- a/source/slang/slang.vcxproj +++ b/source/slang/slang.vcxproj @@ -195,8 +195,6 @@ <ClInclude Include="slang-ast-decl.h" /> <ClInclude Include="slang-ast-dump.h" /> <ClInclude Include="slang-ast-expr.h" /> - <ClInclude Include="slang-ast-generated-macro.h" /> - <ClInclude Include="slang-ast-generated.h" /> <ClInclude Include="slang-ast-modifier.h" /> <ClInclude Include="slang-ast-reflect.h" /> <ClInclude Include="slang-ast-stmt.h" /> @@ -217,6 +215,12 @@ <ClInclude Include="slang-emit-source-writer.h" /> <ClInclude Include="slang-emit.h" /> <ClInclude Include="slang-file-system.h" /> + <ClInclude Include="slang-generated-ast-macro.h" /> + <ClInclude Include="slang-generated-ast.h" /> + <ClInclude Include="slang-generated-obj-macro.h" /> + <ClInclude Include="slang-generated-obj.h" /> + <ClInclude Include="slang-generated-value-macro.h" /> + <ClInclude Include="slang-generated-value.h" /> <ClInclude Include="slang-glsl-extension-tracker.h" /> <ClInclude Include="slang-hlsl-intrinsic-set.h" /> <ClInclude Include="slang-image-format-defs.h" /> @@ -281,7 +285,13 @@ <ClInclude Include="slang-preprocessor.h" /> <ClInclude Include="slang-profile-defs.h" /> <ClInclude Include="slang-profile.h" /> + <ClInclude Include="slang-ref-object-generated-ast-macro.h" /> + <ClInclude Include="slang-ref-object-generated-ast.h" /> <ClInclude Include="slang-ref-object-generated-macro.h" /> + <ClInclude Include="slang-ref-object-generated-obj-macro.h" /> + <ClInclude Include="slang-ref-object-generated-obj.h" /> + <ClInclude Include="slang-ref-object-generated-value-macro.h" /> + <ClInclude Include="slang-ref-object-generated-value.h" /> <ClInclude Include="slang-ref-object-generated.h" /> <ClInclude Include="slang-ref-object-reflect.h" /> <ClInclude Include="slang-reflection.h" /> diff --git a/source/slang/slang.vcxproj.filters b/source/slang/slang.vcxproj.filters index d69ff3059..aad88a15f 100644 --- a/source/slang/slang.vcxproj.filters +++ b/source/slang/slang.vcxproj.filters @@ -36,12 +36,6 @@ <ClInclude Include="slang-ast-expr.h"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="slang-ast-generated-macro.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="slang-ast-generated.h"> - <Filter>Header Files</Filter> - </ClInclude> <ClInclude Include="slang-ast-modifier.h"> <Filter>Header Files</Filter> </ClInclude> @@ -102,6 +96,24 @@ <ClInclude Include="slang-file-system.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="slang-generated-ast-macro.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="slang-generated-ast.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="slang-generated-obj-macro.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="slang-generated-obj.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="slang-generated-value-macro.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="slang-generated-value.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="slang-glsl-extension-tracker.h"> <Filter>Header Files</Filter> </ClInclude> @@ -294,9 +306,27 @@ <ClInclude Include="slang-profile.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="slang-ref-object-generated-ast-macro.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="slang-ref-object-generated-ast.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="slang-ref-object-generated-macro.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="slang-ref-object-generated-obj-macro.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="slang-ref-object-generated-obj.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="slang-ref-object-generated-value-macro.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="slang-ref-object-generated-value.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="slang-ref-object-generated.h"> <Filter>Header Files</Filter> </ClInclude> |
