diff options
Diffstat (limited to 'source/slang')
24 files changed, 320 insertions, 391 deletions
diff --git a/source/slang/bytecode.cpp b/source/slang/bytecode.cpp index 52086c76b..e412a5b94 100644 --- a/source/slang/bytecode.cpp +++ b/source/slang/bytecode.cpp @@ -61,7 +61,7 @@ struct BytecodeGenerationPtr T& operator*() { - return *getPtr() + return *getPtr(); } T& operator[](UInt index) diff --git a/source/slang/check.cpp b/source/slang/check.cpp index e22db4186..5c1f7380c 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -538,7 +538,7 @@ namespace Slang if (auto basicType = type->As<BasicExpressionType>()) { // TODO: `void` shouldn't be a basic type, to make this easier to avoid - if (basicType->BaseType == BaseType::Void) + if (basicType->baseType == BaseType::Void) { // TODO(tfoley): pick the right diagnostic message if (!isRewriteMode()) @@ -723,7 +723,7 @@ namespace Slang // TODO(tfoley): If we can compute the size of the array statically, // then we want to check that there aren't too many initializers present - auto toElementType = toArrayType->BaseType; + auto toElementType = toArrayType->baseType; for(auto& arg : fromInitializerListExpr->args) { @@ -778,123 +778,6 @@ namespace Slang // -#if 0 - if (auto toBasicType = toType->AsBasicType()) - { - if (auto fromBasicType = fromType->AsBasicType()) - { - // Conversions between base types are always allowed, - // and the only question is what the cost will be. - - auto toInfo = GetBaseTypeConversionInfo(toBasicType->BaseType); - auto fromInfo = GetBaseTypeConversionInfo(fromBasicType->BaseType); - - // We expect identical types to have been dealt with already. - SLANG_ASSERT(toInfo.kind != fromInfo.kind || toInfo.rank != fromInfo.rank); - - if (outToExpr) - *outToExpr = CreateImplicitCastExpr(toType, fromExpr); - - - if (outCost) - { - // Conversions within the same kind are easist to handle - if (toInfo.kind == fromInfo.kind) - { - // If we are converting to a "larger" type, then - // we are doing a lossless promotion, and otherwise - // we are doing a demotion. - if( toInfo.rank > fromInfo.rank) - *outCost = kConversionCost_RankPromotion; - else - *outCost = kConversionCost_GeneralConversion; - } - // If we are converting from an unsigned integer type to - // a signed integer type that is guaranteed to be larger, - // then that is also a lossless promotion. - else if(toInfo.kind == kBaseTypeConversionKind_Signed - && fromInfo.kind == kBaseTypeConversionKind_Unsigned - && toInfo.rank > fromInfo.rank) - { - // TODO: probably need to weed out cases involving - // "pointer-sized" integers if these are treated - // as distinct from 32- and 64-bit types. - // E.g., there is no guarantee that conversion - // from 32-bit unsigned to pointer-sized signed - // is lossless, because pointers could be 32-bit, - // and the same applies for conversion from - // `uintptr` to `uint64`. - *outCost = kConversionCost_UnsignedToSignedPromotion; - } - // Conversion from signed to unsigned is always lossy, - // but it is preferred over conversions from unsigned - // to signed, for same-size types. - else if(toInfo.kind == kBaseTypeConversionKind_Unsigned - && fromInfo.kind == kBaseTypeConversionKind_Signed - && toInfo.rank >= fromInfo.rank) - { - *outCost = kConversionCost_SignedToUnsignedConversion; - } - // Conversion from an integer to a floating-point type - // is never considered a promotion (even when the value - // would fit in the available bits). - // If the destination type is at least 32 bits we consider - // this a reasonably good conversion, though. - else if (toInfo.kind == kBaseTypeConversionKind_Float - && toInfo.rank >= kBaseTypeConversionRank_Int32) - { - *outCost = kConversionCost_IntegerToFloatConversion; - } - // All other cases are considered as "general" conversions, - // where we don't consider any one conversion better than - // any others. - else - { - *outCost = kConversionCost_GeneralConversion; - } - } - - return true; - } - } - - if (auto toVectorType = toType->AsVectorType()) - { - if (auto fromVectorType = fromType->AsVectorType()) - { - // Conversion between vector types. - - // If element counts don't match, then bail: - if (!ValuesAreEqual(toVectorType->elementCount, fromVectorType->elementCount)) - return false; - - // Otherwise, if we can convert the element types, we are golden - ConversionCost elementCost; - if (CanCoerce(toVectorType->elementType, fromVectorType->elementType, &elementCost)) - { - if (outToExpr) - *outToExpr = CreateImplicitCastExpr(toType, fromExpr); - if (outCost) - *outCost = elementCost; - return true; - } - } - else if (auto fromScalarType = fromType->AsBasicType()) - { - // Conversion from scalar to vector. - // Should allow as long as we can coerce the scalar to our element type. - ConversionCost elementCost; - if (CanCoerce(toVectorType->elementType, fromScalarType, &elementCost)) - { - if (outToExpr) - *outToExpr = CreateImplicitCastExpr(toType, fromExpr); - if (outCost) - *outCost = elementCost + kConversionCost_ScalarToVector; - return true; - } - } - } -#endif if (auto toDeclRefType = toType->As<DeclRefType>()) { @@ -1973,7 +1856,7 @@ namespace Slang // Create a new array type based on the size we found, // and install it into our type. varDecl->type.type = getArrayType( - arrayType->BaseType, + arrayType->baseType, elementCount); } @@ -2456,7 +2339,7 @@ namespace Slang { return CheckSimpleSubscriptExpr( subscriptExpr, - baseArrayType->BaseType); + baseArrayType->baseType); } else if (auto vecType = baseType->As<VectorExpressionType>()) { @@ -2769,8 +2652,8 @@ namespace Slang { if (auto rightBasic = right->As<BasicExpressionType>()) { - auto leftFlavor = leftBasic->BaseType; - auto rightFlavor = rightBasic->BaseType; + auto leftFlavor = leftBasic->baseType; + auto rightFlavor = rightBasic->baseType; // TODO(tfoley): Need a special-case rule here that if // either operand is of type `half`, then we promote @@ -4779,8 +4662,8 @@ namespace Slang auto targetScalarType = targetArithType->GetScalarType(); auto exprScalarType = exprArithType->GetScalarType(); - if (!IsNumeric(exprScalarType->BaseType)) goto fail; - if (!IsNumeric(targetScalarType->BaseType)) goto fail; + if (!IsNumeric(exprScalarType->baseType)) goto fail; + if (!IsNumeric(targetScalarType->baseType)) goto fail; // TODO(tfoley): this checking is incomplete here, and could // lead to downstream compilation failures @@ -4997,6 +4880,19 @@ namespace Slang return expr; } + RefPtr<Expr> lookupResultFailure( + MemberExpr* expr, + QualType const& baseType) + { + if (!isRewriteMode()) + { + getSink()->diagnose(expr, Diagnostics::noMemberOfNameInType, expr->name, baseType); + } + expr->type = QualType(getSession()->getErrorType()); + return expr; + + } + RefPtr<Expr> visitMemberExpr(MemberExpr * expr) { expr->BaseExpression = CheckExpr(expr->BaseExpression); @@ -5043,7 +4939,7 @@ namespace Slang this, expr->name, aggTypeDeclRef); if (!lookupResult.isValid()) { - goto fail; + return lookupResultFailure(expr, baseType); } // TODO: need to filter for declarations that are valid to refer @@ -5068,7 +4964,7 @@ namespace Slang this, expr->name, aggTypeDeclRef); if (!lookupResult.isValid()) { - goto fail; + return lookupResultFailure(expr, baseType); } return createLookupResultExpr( @@ -5078,13 +4974,7 @@ namespace Slang } // catch-all - fail: - if (!isRewriteMode()) - { - getSink()->diagnose(expr, Diagnostics::noMemberOfNameInType, expr->name, baseType); - } - expr->type = QualType(getSession()->getErrorType()); - return expr; + return lookupResultFailure(expr, baseType); } // All remaining cases assume we have a `BasicType` else if (!baseType->AsBasicType()) diff --git a/source/slang/compiler.cpp b/source/slang/compiler.cpp index b8830c0b4..d7de5c42e 100644 --- a/source/slang/compiler.cpp +++ b/source/slang/compiler.cpp @@ -1,6 +1,7 @@ // Compiler.cpp : Defines the entry point for the console application. // #include "../core/basic.h" +#include "../core/platform.h" #include "../core/slang-io.h" #include "compiler.h" #include "lexer.h" @@ -12,21 +13,43 @@ #include "reflection.h" #include "emit.h" -// Utilities for pass-through modes -#include "../slang-glslang/slang-glslang.h" +// Enable calling through to `fxc` to +// generate code on Windows. +#ifdef _WIN32 + #define WIN32_LEAN_AND_MEAN + #define NOMINMAX + #include <Windows.h> + #undef WIN32_LEAN_AND_MEAN + #undef NOMINMAX + #include <d3dcompiler.h> + #ifndef SLANG_ENABLE_DXBC_SUPPORT + #define SLANG_ENABLE_DXBC_SUPPORT 1 + #endif +#endif +// +// Otherwise, don't enable DXBC by default: +#ifndef SLANG_ENABLE_DXBC_SUPPORT + #define SLANG_ENABLE_DXBC_SUPPORT 0 +#endif +// Enable calling through to `glslang` on +// all platforms. +#ifndef SLANG_ENABLE_GLSLANG_SUPPORT + #define SLANG_ENABLE_GLSLANG_SUPPORT 1 +#endif -#ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#define NOMINMAX -#include <Windows.h> -#undef WIN32_LEAN_AND_MEAN -#undef NOMINMAX -#include <d3dcompiler.h> +#if SLANG_ENABLE_GLSLANG_SUPPORT +#include "../slang-glslang/slang-glslang.h" #endif -#include <io.h> +// Includes to allow us to control console +// output when writing assembly dumps. #include <fcntl.h> +#ifdef _WIN32 +#include <io.h> +#else +#include <unistd.h> +#endif #ifdef _MSC_VER #pragma warning(disable: 4996) @@ -189,7 +212,7 @@ namespace Slang } } -#ifdef _WIN32 +#if SLANG_ENABLE_DXBC_SUPPORT HMODULE loadD3DCompilerDLL(CompileRequest* request) { char const* libraryName = "d3dcompiler_47"; @@ -264,28 +287,6 @@ namespace Slang return data; } -#if 0 - List<uint8_t> EmitDXBytecode( - ExtraContext& context) - { - if(context.getTranslationUnitOptions().entryPoints.Count() != 1) - { - if(context.getTranslationUnitOptions().entryPoints.Count() == 0) - { - // TODO(tfoley): need to write diagnostics into this whole thing... - fprintf(stderr, "no entry point specified\n"); - } - else - { - fprintf(stderr, "multiple entry points specified\n"); - } - return List<uint8_t>(); - } - - return EmitDXBytecodeForEntryPoint(context, context.getTranslationUnitOptions().entryPoints[0]); - } -#endif - String dissassembleDXBC( CompileRequest* compileRequest, void const* data, @@ -345,32 +346,16 @@ namespace Slang return result; } - -#if 0 - String EmitDXBytecodeAssembly( - ExtraContext& context) - { - if(context.getTranslationUnitOptions().entryPoints.Count() == 0) - { - // TODO(tfoley): need to write diagnostics into this whole thing... - fprintf(stderr, "no entry point specified\n"); - return ""; - } - - StringBuilder sb; - for (auto entryPoint : context.getTranslationUnitOptions().entryPoints) - { - sb << EmitDXBytecodeAssemblyForEntryPoint(context, entryPoint); - } - return sb.ProduceString(); - } #endif - HMODULE loadGLSLCompilerDLL(CompileRequest* request) +#if SLANG_ENABLE_GLSLANG_SUPPORT + + SharedLibrary loadGLSLCompilerDLL(CompileRequest* request) { char const* libraryName = "slang-glslang"; // TODO(tfoley): let user specify version of glslang DLL to use. - HMODULE glslCompiler = LoadLibraryA(libraryName); + + SharedLibrary glslCompiler = SharedLibrary::load(libraryName); if (!glslCompiler) { request->mSink.diagnose(SourceLoc(), Diagnostics::failedToLoadDynamicLibrary, libraryName); @@ -378,9 +363,9 @@ namespace Slang return glslCompiler; } - HMODULE getGLSLCompilerDLL(CompileRequest* request) + SharedLibrary getGLSLCompilerDLL(CompileRequest* request) { - static HMODULE glslCompiler = loadGLSLCompilerDLL(request); + static SharedLibrary glslCompiler = loadGLSLCompilerDLL(request); return glslCompiler; } @@ -393,11 +378,11 @@ namespace Slang static glslang_CompileFunc glslang_compile = nullptr; if (!glslang_compile) { - HMODULE glslCompiler = getGLSLCompilerDLL(slangCompileRequest); + SharedLibrary glslCompiler = getGLSLCompilerDLL(slangCompileRequest); if (!glslCompiler) return 1; - glslang_compile = (glslang_CompileFunc)GetProcAddress(glslCompiler, "glslang_compile"); + glslang_compile = (glslang_CompileFunc) glslCompiler.findFuncByName("glslang_compile"); if (!glslang_compile) return 1; } @@ -532,6 +517,7 @@ namespace Slang } break; +#if SLANG_ENABLE_DXBC_SUPPORT case CodeGenTarget::DXBytecode: { List<uint8_t> code = EmitDXBytecodeForEntryPoint(entryPoint); @@ -547,6 +533,7 @@ namespace Slang result = CompileResult(code); } break; +#endif case CodeGenTarget::SPIRV: { @@ -712,6 +699,7 @@ namespace Slang switch (compileRequest->Target) { + #if SLANG_ENABLE_DXBC_SUPPORT case CodeGenTarget::DXBytecode: { String assembly = dissassembleDXBC(compileRequest, @@ -720,6 +708,7 @@ namespace Slang writeOutputToConsole(compileRequest, assembly); } break; + #endif case CodeGenTarget::SPIRV: { @@ -738,7 +727,9 @@ namespace Slang else { // Redirecting stdout to a file, so do the usual thing + #ifdef _WIN32 _setmode(stdoutFileDesc, _O_BINARY); + #endif writeOutputFile( compileRequest, stdout, @@ -955,10 +946,6 @@ namespace Slang dumpIntermediateText(compileRequest, data, size, ".spv.asm"); break; - case CodeGenTarget::DXBytecodeAssembly: - dumpIntermediateText(compileRequest, data, size, ".dxbc.asm"); - break; - case CodeGenTarget::SlangIRAssembly: dumpIntermediateText(compileRequest, data, size, ".slang-ir.asm"); break; @@ -971,6 +958,11 @@ namespace Slang } break; + #if SLANG_ENABLE_DXBC_SUPPORT + case CodeGenTarget::DXBytecodeAssembly: + dumpIntermediateText(compileRequest, data, size, ".dxbc.asm"); + break; + case CodeGenTarget::DXBytecode: dumpIntermediateBinary(compileRequest, data, size, ".dxbc"); { @@ -978,6 +970,7 @@ namespace Slang dumpIntermediateText(compileRequest, dxbcAssembly.begin(), dxbcAssembly.Length(), ".dxbc.asm"); } break; + #endif case CodeGenTarget::SlangIR: dumpIntermediateBinary(compileRequest, data, size, ".slang-ir"); diff --git a/source/slang/core.meta.slang.cpp b/source/slang/core.meta.slang.h index cf2052d3c..cf2052d3c 100644 --- a/source/slang/core.meta.slang.cpp +++ b/source/slang/core.meta.slang.h diff --git a/source/slang/diagnostics.cpp b/source/slang/diagnostics.cpp index 65161db1d..da703e1b9 100644 --- a/source/slang/diagnostics.cpp +++ b/source/slang/diagnostics.cpp @@ -108,7 +108,7 @@ static void formatDiagnosticMessage(StringBuilder& sb, char const* format, int a if (!*spanEnd) return; - SLANG_API(*spanEnd == '$'); + SLANG_ASSERT(*spanEnd == '$'); spanEnd++; int d = *spanEnd++; switch (d) diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 26b3b925b..d4c1be706 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -488,7 +488,7 @@ struct EmitVisitor void Emit(IntegerLiteralValue value) { char buffer[32]; - sprintf(buffer, "%lld", value); + sprintf(buffer, "%lld", (long long int)value); Emit(buffer); } @@ -823,7 +823,7 @@ struct EmitVisitor { if(auto basicElementType = type->As<BasicExpressionType>()) { - switch (basicElementType->BaseType) + switch (basicElementType->baseType) { case BaseType::Float: // no prefix @@ -1043,7 +1043,7 @@ struct EmitVisitor void visitBasicExpressionType(BasicExpressionType* basicType, TypeEmitArg const& arg) { auto declarator = arg.declarator; - switch (basicType->BaseType) + switch (basicType->baseType) { case BaseType::Void: Emit("void"); break; case BaseType::Int: Emit("int"); break; @@ -1208,7 +1208,7 @@ struct EmitVisitor } - emitTypeImpl(arrayType->BaseType, &arrayDeclarator); + emitTypeImpl(arrayType->baseType, &arrayDeclarator); } void EmitType( diff --git a/source/slang/glsl.meta.slang.cpp b/source/slang/glsl.meta.slang.h index e43a51ea9..e43a51ea9 100644 --- a/source/slang/glsl.meta.slang.cpp +++ b/source/slang/glsl.meta.slang.h diff --git a/source/slang/hlsl.meta.slang.cpp b/source/slang/hlsl.meta.slang.h index 49254ac60..49254ac60 100644 --- a/source/slang/hlsl.meta.slang.cpp +++ b/source/slang/hlsl.meta.slang.h diff --git a/source/slang/ir.h b/source/slang/ir.h index a557e22f5..9c3124478 100644 --- a/source/slang/ir.h +++ b/source/slang/ir.h @@ -226,7 +226,7 @@ struct IRInst // All existing uses of `IRValue` should move to `IRInst` typedef IRInst IRValue; -typedef long long IRIntegerValue; +typedef int64_t IRIntegerValue; typedef double IRFloatingPointValue; struct IRConstant : IRInst diff --git a/source/slang/lexer.h b/source/slang/lexer.h index 9ea793d73..23eddf04e 100644 --- a/source/slang/lexer.h +++ b/source/slang/lexer.h @@ -114,7 +114,7 @@ namespace Slang String getStringLiteralTokenValue(Token const& token); String getFileNameTokenValue(Token const& token); - typedef long long IntegerLiteralValue; + typedef int64_t IntegerLiteralValue; typedef double FloatingPointLiteralValue; IntegerLiteralValue getIntegerLiteralValue(Token const& token, String* outSuffix = 0); diff --git a/source/slang/lookup.h b/source/slang/lookup.h index b8223caa6..be7cb30bc 100644 --- a/source/slang/lookup.h +++ b/source/slang/lookup.h @@ -1,7 +1,7 @@ #ifndef SLANG_LOOKUP_H_INCLUDED #define SLANG_LOOKUP_H_INCLUDED -#include "Syntax.h" +#include "syntax.h" namespace Slang { diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index 464d5d50a..06ad66bc4 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -836,7 +836,7 @@ struct ValLoweringVisitor : ValVisitor<ValLoweringVisitor, LoweredValInfo, Lower LoweredTypeInfo visitBasicExpressionType(BasicExpressionType* type) { - return getBuilder()->getBaseType(type->BaseType); + return getBuilder()->getBaseType(type->baseType); } LoweredTypeInfo visitVectorExpressionType(VectorExpressionType* type) @@ -876,7 +876,7 @@ struct ValLoweringVisitor : ValVisitor<ValLoweringVisitor, LoweredValInfo, Lower LoweredTypeInfo visitArrayExpressionType(ArrayExpressionType* type) { - auto loweredElementType = lowerType(context, type->BaseType); + auto loweredElementType = lowerType(context, type->baseType); if (auto elementCount = type->ArrayLength) { auto irElementCount = lowerSimpleVal(context, elementCount); @@ -984,7 +984,7 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo> // as the visitor itself. LoweredValInfo lowerSubExpr(Expr* expr) { - return dispatch(expr); + return this->dispatch(expr); } @@ -2306,7 +2306,8 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> template<typename D> DeclRef<D> createDefaultSpecializedDeclRef(D* decl) { - return createDefaultSpecializedDeclRefImpl(decl).As<D>(); + DeclRef<Decl> declRef = createDefaultSpecializedDeclRefImpl(decl); + return declRef.As<D>(); } diff --git a/source/slang/lower.cpp b/source/slang/lower.cpp index 391221f47..85f19f14c 100644 --- a/source/slang/lower.cpp +++ b/source/slang/lower.cpp @@ -36,6 +36,103 @@ struct CloneVisitor // +// + +class TupleExpr; +class TupleVarDecl; +class VaryingTupleExpr; +class VaryingTupleVarDecl; + + +// The result of lowering a declaration will usually be a declaration, +// but it might also be a "tuple" declaration, in cases where we needed +// to sclarize (or partially scalarize) things to guarantee validity. +struct LoweredDecl +{ + enum class Flavor + { + Decl, // A single declaration (the default case) + Tuple, // A `TupleVarDecl` representing multiple decls + VaryingTuple, // A `VaryingTupleVarDecl` representing multiple decls + }; + + LoweredDecl() + : flavor(Flavor::Decl) + {} + + LoweredDecl(Decl* decl) + : value(decl) + , flavor(Flavor::Decl) + {} + + LoweredDecl(TupleVarDecl* decl) + : value((RefObject*) decl) + , flavor(Flavor::Tuple) + {} + + LoweredDecl(VaryingTupleVarDecl* decl) + : value((RefObject*) decl) + , flavor(Flavor::VaryingTuple) + {} + + Flavor getFlavor() const { return flavor; } + RefObject* getValue() const { return value; } + + Decl* getDecl() const + { + SLANG_ASSERT(getFlavor() == Flavor::Decl); + return (Decl*) value.Ptr(); + } + + TupleVarDecl* getTupleDecl() const + { + SLANG_ASSERT(getFlavor() == Flavor::Tuple); + return (TupleVarDecl*) value.Ptr(); + } + + VaryingTupleVarDecl* getVaryingTupleDecl() const + { + SLANG_ASSERT(getFlavor() == Flavor::VaryingTuple); + return (VaryingTupleVarDecl*) value.Ptr(); + } + + Decl* asDecl() const + { + return (getFlavor() == Flavor::Decl) ? getDecl() : nullptr; + } + + TupleVarDecl* asTupleDecl() const + { + return (getFlavor() == Flavor::Tuple) ? getTupleDecl() : nullptr; + } + + VaryingTupleVarDecl* asVaryingTupleDecl() const + { + return (getFlavor() == Flavor::VaryingTuple) ? getVaryingTupleDecl() : nullptr; + } + +private: + RefPtr<RefObject> value; + Flavor flavor; +}; + +struct LoweredDeclRef +{ +public: + LoweredDecl decl; + RefPtr<Substitutions> substitutions; + + LoweredDecl getDecl() { return decl; } + + template<typename T> + DeclRef<T> As() + { + return DeclRef<Decl>(decl.getDecl(), substitutions).As<T>(); + } +}; + +// + template<typename V> struct StructuralTransformVisitorBase { @@ -54,7 +151,8 @@ struct StructuralTransformVisitorBase template<typename T> DeclRef<T> transformDeclField(DeclRef<T> const& decl) { - return visitor->translateDeclRef(decl).As<T>(); + LoweredDeclRef declRef = visitor->translateDeclRef(decl); + return declRef.As<T>(); } TypeExp transformSyntaxField(TypeExp const& typeExp) @@ -89,7 +187,8 @@ struct StructuralTransformVisitorBase RefPtr<ScopeDecl> transformSyntaxField(ScopeDecl* decl) { if(!decl) return nullptr; - return visitor->transformSyntaxField(decl).As<ScopeDecl>(); + RefPtr<Decl> transformed = visitor->transformSyntaxField(decl); + return transformed.As<ScopeDecl>(); } template<typename T> @@ -104,6 +203,7 @@ struct StructuralTransformVisitorBase } }; +#if 0 template<typename V> RefPtr<Stmt> structuralTransform( Stmt* stmt, @@ -113,6 +213,7 @@ RefPtr<Stmt> structuralTransform( transformer.visitor = visitor; return transformer.dispatch(stmt); } +#endif template<typename V> struct StructuralTransformExprVisitor @@ -121,21 +222,26 @@ struct StructuralTransformExprVisitor { void transformFields(Expr* result, Expr* obj) { - result->type = transformSyntaxField(obj->type); + result->type = this->transformSyntaxField(obj->type); } +#define ABSTRACT_SYNTAX_CLASS(NAME, BASE, ...) \ + void transformFields(NAME* result, NAME* obj) { \ + this->transformFields((BASE*) result, (BASE*) obj); \ + /* end */ + #define SYNTAX_CLASS(NAME, BASE, ...) \ - RefPtr<Expr> visit##NAME(NAME* obj) { \ + RefPtr<Expr> visit##NAME(NAME* obj) { \ RefPtr<NAME> result = new NAME(*obj); \ transformFields(result, obj); \ return result; \ } \ - void transformFields(NAME* result, NAME* obj) { \ - transformFields((BASE*) result, (BASE*) obj); \ + ABSTRACT_SYNTAX_CLASS(NAME, BASE) \ + /* end */ -#define SYNTAX_FIELD(TYPE, NAME) result->NAME = transformSyntaxField(obj->NAME); -#define DECL_FIELD(TYPE, NAME) result->NAME = transformDeclField(obj->NAME); +#define SYNTAX_FIELD(TYPE, NAME) result->NAME = this->transformSyntaxField(obj->NAME); +#define DECL_FIELD(TYPE, NAME) result->NAME = this->transformDeclField(obj->NAME); #define FIELD(TYPE, NAME) /* empty */ @@ -158,100 +264,6 @@ RefPtr<Expr> structuralTransform( return transformer.dispatch(expr); } -// - -class TupleExpr; -class TupleVarDecl; -class VaryingTupleExpr; -class VaryingTupleVarDecl; - - -// The result of lowering a declaration will usually be a declaration, -// but it might also be a "tuple" declaration, in cases where we needed -// to sclarize (or partially scalarize) things to guarantee validity. -struct LoweredDecl -{ - enum class Flavor - { - Decl, // A single declaration (the default case) - Tuple, // A `TupleVarDecl` representing multiple decls - VaryingTuple, // A `VaryingTupleVarDecl` representing multiple decls - }; - - LoweredDecl() - : flavor(Flavor::Decl) - {} - - LoweredDecl(Decl* decl) - : value(decl) - , flavor(Flavor::Decl) - {} - - LoweredDecl(TupleVarDecl* decl) - : value((RefObject*) decl) - , flavor(Flavor::Tuple) - {} - - LoweredDecl(VaryingTupleVarDecl* decl) - : value((RefObject*) decl) - , flavor(Flavor::VaryingTuple) - {} - - Flavor getFlavor() const { return flavor; } - RefObject* getValue() const { return value; } - - Decl* getDecl() const - { - SLANG_ASSERT(getFlavor() == Flavor::Decl); - return (Decl*) value.Ptr(); - } - - TupleVarDecl* getTupleDecl() const - { - SLANG_ASSERT(getFlavor() == Flavor::Tuple); - return (TupleVarDecl*) value.Ptr(); - } - - VaryingTupleVarDecl* getVaryingTupleDecl() const - { - SLANG_ASSERT(getFlavor() == Flavor::VaryingTuple); - return (VaryingTupleVarDecl*) value.Ptr(); - } - - Decl* asDecl() const - { - return (getFlavor() == Flavor::Decl) ? getDecl() : nullptr; - } - - TupleVarDecl* asTupleDecl() const - { - return (getFlavor() == Flavor::Tuple) ? getTupleDecl() : nullptr; - } - - VaryingTupleVarDecl* asVaryingTupleDecl() const - { - return (getFlavor() == Flavor::VaryingTuple) ? getVaryingTupleDecl() : nullptr; - } - -private: - RefPtr<RefObject> value; - Flavor flavor; -}; - -struct LoweredDeclRef -{ -public: - LoweredDecl decl; - RefPtr<Substitutions> substitutions; - - LoweredDecl getDecl() { return decl; } - - template<typename T> - DeclRef<T> As() - { - return DeclRef<Decl>(decl.getDecl(), substitutions).As<T>(); - } -}; // The result of lowering an exrpession will usually be just a single @@ -321,9 +333,10 @@ struct LoweredExpr return (getFlavor() == Flavor::VaryingTuple) ? getVaryingTupleExpr() : nullptr; } - bool operator!() + // Allow use in boolean contexts + operator void*() { - return !value; + return value.Ptr(); } private: @@ -754,7 +767,7 @@ struct LoweringVisitor RefPtr<Type> visitArrayExpressionType(ArrayExpressionType* type) { RefPtr<ArrayExpressionType> loweredType = Slang::getArrayType( - lowerType(type->BaseType), + lowerType(type->baseType), lowerVal(type->ArrayLength).As<IntVal>()); return loweredType; } @@ -1074,7 +1087,7 @@ struct LoweringVisitor if (auto rightVecType = rightType->As<VectorExpressionType>()) { // RHS type was a vector - if (auto leftElemVecType = leftArrayType->BaseType->As<VectorExpressionType>()) + if (auto leftElemVecType = leftArrayType->baseType->As<VectorExpressionType>()) { // LHS element type was also a vector, so this is a "scalar splat // to array" case. @@ -1102,7 +1115,7 @@ struct LoweringVisitor swizzleExpr->elementIndices[0] = ee; auto convertedArgExpr = convertExprForAssignmentWithFixups( - leftArrayType->BaseType, + leftArrayType->baseType, swizzleExpr); ctorExpr->Arguments.Add(convertedArgExpr); @@ -1222,7 +1235,7 @@ struct LoweringVisitor if (auto rightVecType = rightType->As<VectorExpressionType>()) { // RHS type was a vector - if (auto leftElemVecType = leftArrayType->BaseType->As<VectorExpressionType>()) + if (auto leftElemVecType = leftArrayType->baseType->As<VectorExpressionType>()) { // LHS element type was also a vector, so this is a "scalar splat // to array" case. @@ -1243,7 +1256,7 @@ struct LoweringVisitor // LHS array element RefPtr<IndexExpr> arrayElemExpr = new IndexExpr(); arrayElemExpr->loc = leftExpr->loc; - arrayElemExpr->type.type = leftArrayType->BaseType; + arrayElemExpr->type.type = leftArrayType->baseType; arrayElemExpr->BaseExpression = leftExpr; arrayElemExpr->IndexExpression = createConstIntExpr(ee); @@ -1495,7 +1508,7 @@ struct LoweringVisitor { if (auto arrayType = type->As<ArrayExpressionType>()) { - return arrayType->BaseType; + return arrayType->baseType; } return nullptr; } @@ -1702,7 +1715,7 @@ struct LoweringVisitor while (auto arrayType = varType->As<ArrayExpressionType>()) { - varType = arrayType->BaseType; + varType = arrayType->baseType; } if (auto constantBufferType = varType->As<ConstantBufferType>()) @@ -2834,7 +2847,7 @@ struct LoweringVisitor auto type = inType; while (auto arrayType = type->As<ArrayExpressionType>()) { - type = arrayType->BaseType; + type = arrayType->baseType; } return type; } @@ -2848,7 +2861,7 @@ struct LoweringVisitor { while (auto arrayType = type->As<ArrayExpressionType>()) { - type = arrayType->BaseType; + type = arrayType->baseType; } if (auto textureTypeBase = type->As<TextureTypeBase>()) @@ -3065,7 +3078,7 @@ struct LoweringVisitor arraySpec.elementCount = arrayType->ArrayLength; TupleSecondaryVarInfo subInfo = info; - subInfo.tupleType = arrayType->BaseType; + subInfo.tupleType = arrayType->baseType; subInfo.arraySpecs = &arraySpec; createTupleTypeSecondaryVarDecls(subInfo); return; @@ -3685,7 +3698,7 @@ struct LoweringVisitor { if (auto baseType = type->As<BasicExpressionType>()) { - switch (baseType->BaseType) + switch (baseType->baseType) { default: return false; @@ -4108,7 +4121,7 @@ struct LoweringVisitor // heterogeneous stuff... return lowerShaderParameterToGLSLGLobalsRec( arrayInfo, - arrayType->BaseType, + arrayType->baseType, varLayout); } else if (auto declRefType = varType->As<DeclRefType>()) diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp index a00520c05..8cc93fdd2 100644 --- a/source/slang/parameter-binding.cpp +++ b/source/slang/parameter-binding.cpp @@ -413,7 +413,7 @@ RefPtr<Type> tryGetEffectiveTypeForGLSLVaryingInput( // Unwrap array type, if prsent if( auto arrayType = type->As<ArrayExpressionType>() ) { - type = arrayType->BaseType.Ptr(); + type = arrayType->baseType.Ptr(); } } break; @@ -452,7 +452,7 @@ RefPtr<Type> tryGetEffectiveTypeForGLSLVaryingOutput( // Unwrap array type, if prsent if( auto arrayType = type->As<ArrayExpressionType>() ) { - type = arrayType->BaseType.Ptr(); + type = arrayType->baseType.Ptr(); } } break; @@ -1213,13 +1213,13 @@ static RefPtr<TypeLayout> processEntryPointParameter( auto elementCount = (UInt) GetIntVal(arrayType->ArrayLength); // We use the first element to derive the layout for the element type - auto elementTypeLayout = processEntryPointParameter(context, arrayType->BaseType, state, varLayout); + auto elementTypeLayout = processEntryPointParameter(context, arrayType->baseType, state, varLayout); // We still walk over subsequent elements to make sure they consume resources // as needed for( UInt ii = 1; ii < elementCount; ++ii ) { - processEntryPointParameter(context, arrayType->BaseType, state, nullptr); + processEntryPointParameter(context, arrayType->baseType, state, nullptr); } RefPtr<ArrayTypeLayout> arrayTypeLayout = new ArrayTypeLayout(); diff --git a/source/slang/parameter-binding.h b/source/slang/parameter-binding.h index 66c8053d3..264163974 100644 --- a/source/slang/parameter-binding.h +++ b/source/slang/parameter-binding.h @@ -4,7 +4,7 @@ #include "../core/basic.h" #include "syntax.h" -#include "../../Slang.h" +#include "../../slang.h" namespace Slang { diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp index 2381682aa..38d9c744d 100644 --- a/source/slang/parser.cpp +++ b/source/slang/parser.cpp @@ -1,4 +1,4 @@ -#include "Parser.h" +#include "parser.h" #include <assert.h> diff --git a/source/slang/profile.cpp b/source/slang/profile.cpp index 4420a722a..6090ddc2e 100644 --- a/source/slang/profile.cpp +++ b/source/slang/profile.cpp @@ -1,5 +1,5 @@ // profile.cpp -#include "Profile.h" +#include "profile.h" namespace Slang { diff --git a/source/slang/reflection.cpp b/source/slang/reflection.cpp index b63240506..5e18e8cfd 100644 --- a/source/slang/reflection.cpp +++ b/source/slang/reflection.cpp @@ -223,7 +223,7 @@ SLANG_API SlangReflectionType* spReflectionType_GetElementType(SlangReflectionTy if(auto arrayType = dynamic_cast<ArrayExpressionType*>(type)) { - return (SlangReflectionType*) arrayType->BaseType.Ptr(); + return (SlangReflectionType*) arrayType->baseType.Ptr(); } else if( auto constantBufferType = dynamic_cast<ConstantBufferType*>(type)) { @@ -299,7 +299,7 @@ SLANG_API SlangScalarType spReflectionType_GetScalarType(SlangReflectionType* in if(auto basicType = dynamic_cast<BasicExpressionType*>(type)) { - switch (basicType->BaseType) + switch (basicType->baseType) { #define CASE(BASE, TAG) \ case BaseType::BASE: return SLANG_SCALAR_TYPE_##TAG @@ -330,7 +330,7 @@ SLANG_API SlangResourceShape spReflectionType_GetResourceShape(SlangReflectionTy while(auto arrayType = type->As<ArrayExpressionType>()) { - type = arrayType->BaseType.Ptr(); + type = arrayType->baseType.Ptr(); } if(auto textureType = type->As<TextureTypeBase>()) @@ -363,7 +363,7 @@ SLANG_API SlangResourceAccess spReflectionType_GetResourceAccess(SlangReflection while(auto arrayType = type->As<ArrayExpressionType>()) { - type = arrayType->BaseType.Ptr(); + type = arrayType->baseType.Ptr(); } if(auto textureType = type->As<TextureTypeBase>()) @@ -399,7 +399,7 @@ SLANG_API SlangReflectionType* spReflectionType_GetResourceResultType(SlangRefle while(auto arrayType = type->As<ArrayExpressionType>()) { - type = arrayType->BaseType.Ptr(); + type = arrayType->baseType.Ptr(); } if (auto textureType = type->As<TextureTypeBase>()) @@ -1100,11 +1100,11 @@ static void emitReflectionTypeInfoJSON( { switch( type->getKind() ) { - case SLANG_TYPE_KIND_SAMPLER_STATE: + case slang::TypeReflection::Kind::SamplerState: write(writer, "\"kind\": \"samplerState\""); break; - case SLANG_TYPE_KIND_RESOURCE: + case slang::TypeReflection::Kind::Resource: { auto shape = type->getResourceShape(); auto access = type->getResourceAccess(); @@ -1163,7 +1163,7 @@ static void emitReflectionTypeInfoJSON( } break; - case SLANG_TYPE_KIND_CONSTANT_BUFFER: + case slang::TypeReflection::Kind::ConstantBuffer: write(writer, "\"kind\": \"constantBuffer\""); write(writer, ",\n"); write(writer, "\"elementType\": "); @@ -1172,7 +1172,7 @@ static void emitReflectionTypeInfoJSON( type->getElementType()); break; - case SLANG_TYPE_KIND_TEXTURE_BUFFER: + case slang::TypeReflection::Kind::TextureBuffer: write(writer, "\"kind\": \"textureBuffer\""); write(writer, ",\n"); write(writer, "\"elementType\": "); @@ -1181,7 +1181,7 @@ static void emitReflectionTypeInfoJSON( type->getElementType()); break; - case SLANG_TYPE_KIND_SHADER_STORAGE_BUFFER: + case slang::TypeReflection::Kind::ShaderStorageBuffer: write(writer, "\"kind\": \"shaderStorageBuffer\""); write(writer, ",\n"); write(writer, "\"elementType\": "); @@ -1190,7 +1190,7 @@ static void emitReflectionTypeInfoJSON( type->getElementType()); break; - case SLANG_TYPE_KIND_SCALAR: + case slang::TypeReflection::Kind::Scalar: write(writer, "\"kind\": \"scalar\""); write(writer, ",\n"); emitReflectionScalarTypeInfoJSON( @@ -1198,7 +1198,7 @@ static void emitReflectionTypeInfoJSON( type->getScalarType()); break; - case SLANG_TYPE_KIND_VECTOR: + case slang::TypeReflection::Kind::Vector: write(writer, "\"kind\": \"vector\""); write(writer, ",\n"); write(writer, "\"elementCount\": "); @@ -1210,7 +1210,7 @@ static void emitReflectionTypeInfoJSON( type->getElementType()); break; - case SLANG_TYPE_KIND_MATRIX: + case slang::TypeReflection::Kind::Matrix: write(writer, "\"kind\": \"matrix\""); write(writer, ",\n"); write(writer, "\"rowCount\": "); @@ -1225,7 +1225,7 @@ static void emitReflectionTypeInfoJSON( type->getElementType()); break; - case SLANG_TYPE_KIND_ARRAY: + case slang::TypeReflection::Kind::Array: { auto arrayType = type; write(writer, "\"kind\": \"array\""); @@ -1238,7 +1238,7 @@ static void emitReflectionTypeInfoJSON( } break; - case SLANG_TYPE_KIND_STRUCT: + case slang::TypeReflection::Kind::Struct: { write(writer, "\"kind\": \"struct\",\n"); write(writer, "\"fields\": [\n"); @@ -1274,7 +1274,7 @@ static void emitReflectionTypeLayoutInfoJSON( emitReflectionTypeInfoJSON(writer, typeLayout->getType()); break; - case SLANG_TYPE_KIND_ARRAY: + case slang::TypeReflection::Kind::Array: { auto arrayTypeLayout = typeLayout; auto elementTypeLayout = arrayTypeLayout->getElementTypeLayout(); @@ -1296,7 +1296,7 @@ static void emitReflectionTypeLayoutInfoJSON( } break; - case SLANG_TYPE_KIND_STRUCT: + case slang::TypeReflection::Kind::Struct: { write(writer, "\"kind\": \"struct\",\n"); write(writer, "\"fields\": [\n"); @@ -1316,7 +1316,7 @@ static void emitReflectionTypeLayoutInfoJSON( } break; - case SLANG_TYPE_KIND_CONSTANT_BUFFER: + case slang::TypeReflection::Kind::ConstantBuffer: write(writer, "\"kind\": \"constantBuffer\""); write(writer, ",\n"); write(writer, "\"elementType\": "); @@ -1325,7 +1325,7 @@ static void emitReflectionTypeLayoutInfoJSON( typeLayout->getElementTypeLayout()); break; - case SLANG_TYPE_KIND_TEXTURE_BUFFER: + case slang::TypeReflection::Kind::TextureBuffer: write(writer, "\"kind\": \"textureBuffer\""); write(writer, ",\n"); write(writer, "\"elementType\": "); @@ -1334,7 +1334,7 @@ static void emitReflectionTypeLayoutInfoJSON( typeLayout->getElementTypeLayout()); break; - case SLANG_TYPE_KIND_SHADER_STORAGE_BUFFER: + case slang::TypeReflection::Kind::ShaderStorageBuffer: write(writer, "\"kind\": \"shaderStorageBuffer\""); write(writer, ",\n"); write(writer, "\"elementType\": "); diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp index cf45cbca8..3e526e96c 100644 --- a/source/slang/slang-stdlib.cpp +++ b/source/slang/slang-stdlib.cpp @@ -248,7 +248,7 @@ namespace Slang #define EMIT_LINE_DIRECTIVE() sb << "#line " << (__LINE__+1) << " \"" << path << "\"\n" - #include "core.meta.slang.cpp" + #include "core.meta.slang.h" coreLibraryCode = sb.ProduceString(); return coreLibraryCode; @@ -261,7 +261,7 @@ namespace Slang StringBuilder sb; - #include "hlsl.meta.slang.cpp" + #include "hlsl.meta.slang.h" hlslLibraryCode = sb.ProduceString(); return hlslLibraryCode; @@ -279,7 +279,7 @@ namespace Slang StringBuilder sb; - #include "glsl.meta.slang.cpp" + #include "glsl.meta.slang.h" glslLibraryCode = sb.ProduceString(); return glslLibraryCode; diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index d02f880fd..475802cb1 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -15,7 +15,7 @@ namespace Slang auto basicType = dynamic_cast<const BasicExpressionType*>(type); if (basicType == nullptr) return false; - return basicType->BaseType == BaseType; + return basicType->baseType == this->baseType; } Type* BasicExpressionType::CreateCanonicalType() @@ -28,7 +28,7 @@ namespace Slang { Slang::StringBuilder res; - switch (BaseType) + switch (this->baseType) { case Slang::BaseType::Int: res.Append("int"); @@ -63,21 +63,19 @@ namespace Slang #undef ABSTRACT_SYNTAX_CLASS #define ABSTRACT_SYNTAX_CLASS(NAME, BASE) \ + template<> \ SyntaxClassBase::ClassInfo const SyntaxClassBase::Impl<NAME>::kClassInfo = { #NAME, &SyntaxClassBase::Impl<BASE>::kClassInfo, nullptr }; -#define SYNTAX_CLASS(NAME, BASE) \ - void NAME::accept(NAME::Visitor* visitor, void* extra) \ - { visitor->dispatch_##NAME(this, extra); } \ - void* SyntaxClassBase::Impl<NAME>::createFunc() { return new NAME(); } \ - SyntaxClass<NodeBase> NAME::getClass() { return Slang::getClass<NAME>(); } \ +#define SYNTAX_CLASS(NAME, BASE) \ + void NAME::accept(NAME::Visitor* visitor, void* extra) \ + { visitor->dispatch_##NAME(this, extra); } \ + template<> \ + void* SyntaxClassBase::Impl<NAME>::createFunc() { return new NAME(); } \ + SyntaxClass<NodeBase> NAME::getClass() { return Slang::getClass<NAME>(); } \ + template<> \ SyntaxClassBase::ClassInfo const SyntaxClassBase::Impl<NAME>::kClassInfo = { #NAME, &SyntaxClassBase::Impl<BASE>::kClassInfo, &SyntaxClassBase::Impl<NAME>::createFunc }; -#include "expr-defs.h" -#include "decl-defs.h" -#include "modifier-defs.h" -#include "stmt-defs.h" -#include "type-defs.h" -#include "val-defs.h" +template<> SyntaxClassBase::ClassInfo const SyntaxClassBase::Impl<RefObject>::kClassInfo = { "RefObject", nullptr, nullptr }; ABSTRACT_SYNTAX_CLASS(NodeBase, RefObject); @@ -94,6 +92,14 @@ ABSTRACT_SYNTAX_CLASS(Expr, SyntaxNode); ABSTRACT_SYNTAX_CLASS(Substitutions, SyntaxNode); +#include "expr-defs.h" +#include "decl-defs.h" +#include "modifier-defs.h" +#include "stmt-defs.h" +#include "type-defs.h" +#include "val-defs.h" + + #include "object-meta-end.h" bool SyntaxClassBase::isSubClassOfImpl(SyntaxClassBase const& super) const @@ -278,11 +284,12 @@ void Type::accept(IValVisitor* visitor, void* extra) auto arrType = type->AsArrayType(); if (!arrType) return false; - return (ArrayLength == arrType->ArrayLength && BaseType->Equals(arrType->BaseType.Ptr())); + return (ArrayLength == arrType->ArrayLength && baseType->Equals(arrType->baseType.Ptr())); } + Type* ArrayExpressionType::CreateCanonicalType() { - auto canonicalElementType = BaseType->GetCanonicalType(); + auto canonicalElementType = baseType->GetCanonicalType(); auto canonicalArrayType = getArrayType( canonicalElementType, ArrayLength); @@ -292,16 +299,16 @@ void Type::accept(IValVisitor* visitor, void* extra) int ArrayExpressionType::GetHashCode() { if (ArrayLength) - return (BaseType->GetHashCode() * 16777619) ^ ArrayLength->GetHashCode(); + return (baseType->GetHashCode() * 16777619) ^ ArrayLength->GetHashCode(); else - return BaseType->GetHashCode(); + return baseType->GetHashCode(); } Slang::String ArrayExpressionType::ToString() { if (ArrayLength) - return BaseType->ToString() + "[" + ArrayLength->ToString() + "]"; + return baseType->ToString() + "[" + ArrayLength->ToString() + "]"; else - return BaseType->ToString() + "[]"; + return baseType->ToString() + "[]"; } // DeclRefType @@ -1115,7 +1122,7 @@ void Type::accept(IValVisitor* visitor, void* extra) auto session = elementType->getSession(); auto arrayType = new ArrayExpressionType(); arrayType->setSession(session); - arrayType->BaseType = elementType; + arrayType->baseType = elementType; arrayType->ArrayLength = elementCount; return arrayType; } @@ -1126,7 +1133,7 @@ void Type::accept(IValVisitor* visitor, void* extra) auto session = elementType->getSession(); auto arrayType = new ArrayExpressionType(); arrayType->setSession(session); - arrayType->BaseType = elementType; + arrayType->baseType = elementType; return arrayType; } diff --git a/source/slang/syntax.h b/source/slang/syntax.h index 2fcfe8d39..8d6a1edbc 100644 --- a/source/slang/syntax.h +++ b/source/slang/syntax.h @@ -168,10 +168,12 @@ namespace Slang return (T*)current; } - void operator++() + void operator++(); + #if 0 { current = Adjust(current->next.Ptr()); } + #endif bool operator!=(Iterator other) { @@ -198,7 +200,8 @@ namespace Slang Iterator begin() { return Iterator(modifiers); } Iterator end() { return Iterator(nullptr); } - static Modifier* Adjust(Modifier* modifier) + static Modifier* Adjust(Modifier* modifier); + #if 0 { Modifier* m = modifier; for (;;) @@ -208,6 +211,7 @@ namespace Slang m = m->next.Ptr(); } } + #endif Modifier* modifiers; }; @@ -445,11 +449,11 @@ namespace Slang } // "dynamic cast" to a more specific declaration reference type - template<typename T> - DeclRef<T> As() const + template<typename U> + DeclRef<U> As() const { - DeclRef<T> result; - result.decl = dynamic_cast<T*>(decl); + DeclRef<U> result; + result.decl = dynamic_cast<U*>(decl); result.substitutions = substitutions; return result; } @@ -904,7 +908,7 @@ namespace Slang // inline BaseType GetVectorBaseType(VectorExpressionType* vecType) { - return vecType->elementType->AsBasicType()->BaseType; + return vecType->elementType->AsBasicType()->baseType; } inline int GetVectorSize(VectorExpressionType* vecType) @@ -1011,6 +1015,28 @@ namespace Slang RefPtr<SamplerStateType> getSamplerStateType( Session* session); + + // Definitions that can't come earlier despite + // being in templates, because gcc/clang get angry. + // + template<typename T> + void FilteredModifierList<T>::Iterator::operator++() + { + current = Adjust(current->next.Ptr()); + } + // + template<typename T> + Modifier* FilteredModifierList<T>::Adjust(Modifier* modifier) + { + Modifier* m = modifier; + for (;;) + { + if (!m) return m; + if (dynamic_cast<T*>(m)) return m; + m = m->next.Ptr(); + } + } + } // namespace Slang #endif
\ No newline at end of file diff --git a/source/slang/type-defs.h b/source/slang/type-defs.h index d556e58e4..7883b5c42 100644 --- a/source/slang/type-defs.h +++ b/source/slang/type-defs.h @@ -76,15 +76,14 @@ END_SYNTAX_CLASS() SYNTAX_CLASS(BasicExpressionType, ArithmeticExpressionType) - FIELD(BaseType, BaseType) + FIELD(BaseType, baseType) RAW( BasicExpressionType() {} BasicExpressionType( Slang::BaseType baseType) - { - BaseType = baseType; - } + : baseType(baseType) + {} virtual Slang::String ToString() override; protected: virtual BasicExpressionType* GetScalarType() override; @@ -283,7 +282,7 @@ SIMPLE_SYNTAX_CLASS(GLSLOutputParameterBlockType, VaryingParameterBlockType) SIMPLE_SYNTAX_CLASS(GLSLShaderStorageBufferType, UniformParameterBlockType) SYNTAX_CLASS(ArrayExpressionType, Type) - SYNTAX_FIELD(RefPtr<Type>, BaseType) + SYNTAX_FIELD(RefPtr<Type>, baseType) SYNTAX_FIELD(RefPtr<IntVal>, ArrayLength) RAW( diff --git a/source/slang/type-layout.cpp b/source/slang/type-layout.cpp index ec71df37d..27bcbd174 100644 --- a/source/slang/type-layout.cpp +++ b/source/slang/type-layout.cpp @@ -1168,7 +1168,7 @@ SimpleLayoutInfo GetLayoutImpl( else if(auto basicType = type->As<BasicExpressionType>()) { return GetSimpleLayoutImpl( - rules->GetScalarLayout(basicType->BaseType), + rules->GetScalarLayout(basicType->baseType), type, rules, outTypeLayout); @@ -1229,7 +1229,7 @@ SimpleLayoutInfo GetLayoutImpl( RefPtr<TypeLayout> elementTypeLayout; auto elementInfo = GetLayoutImpl( context, - arrayType->BaseType.Ptr(), + arrayType->baseType.Ptr(), outTypeLayout ? &elementTypeLayout : nullptr); // For layout purposes, we treat an unsized array as an array of zero elements. diff --git a/source/slang/vm.cpp b/source/slang/vm.cpp index 70315e701..65ecefc01 100644 --- a/source/slang/vm.cpp +++ b/source/slang/vm.cpp @@ -332,7 +332,7 @@ void dumpVMFrame(VMFrame* vmFrame) fprintf(stderr, "0x%p: ", regData); - fprintf(stderr, "%%%u ", rr); + fprintf(stderr, "%%%u ", (unsigned int) rr); if (name) { fprintf(stderr, "\"%s\" ", name); |
