diff options
| author | Yong He <yonghe@outlook.com> | 2023-08-04 15:47:39 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-04 15:47:39 -0700 |
| commit | a2d90fb275962da84611160f8ddd74d934a68dbd (patch) | |
| tree | 066084537b9f4fe1f367de100ed6638a88a028c1 /source/slang/slang-mangle.cpp | |
| parent | 17da4f0dec2b86ba3a4bdaf8a2ae112047d23623 (diff) | |
Redesign `DeclRef` and systematic `Val` deduplication (#3049)
* Redesign DeclRef + Deduplicate Val.
* Update project files
* Fix warning.
* Fix.
* Fix.
* Remove `Val::_equalsImplOverride`.
* Rmove `Val::_getHashCodeOverride`.
* Remove `semanticVisitor` param from `resolve`.
* Cleanups.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-mangle.cpp')
| -rw-r--r-- | source/slang/slang-mangle.cpp | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/source/slang/slang-mangle.cpp b/source/slang/slang-mangle.cpp index 4d94d5283..b27a45484 100644 --- a/source/slang/slang-mangle.cpp +++ b/source/slang/slang-mangle.cpp @@ -141,7 +141,7 @@ namespace Slang { if( auto constVal = as<ConstantIntVal>(val) ) { - auto cVal = constVal->value; + auto cVal = constVal->getValue(); if(cVal >= 0 && cVal <= 9 ) { emit(context, (UInt)cVal); @@ -190,13 +190,13 @@ namespace Slang if( auto basicType = dynamicCast<BasicExpressionType>(type) ) { - emitBaseType(context, basicType->baseType); + emitBaseType(context, basicType->getBaseType()); } else if( auto vecType = dynamicCast<VectorExpressionType>(type) ) { emitRaw(context, "v"); - emitSimpleIntVal(context, vecType->elementCount); - emitType(context, vecType->elementType); + emitSimpleIntVal(context, vecType->getElementCount()); + emitType(context, vecType->getElementType()); } else if( auto matType = dynamicCast<MatrixExpressionType>(type) ) { @@ -208,11 +208,11 @@ namespace Slang } else if( auto namedType = dynamicCast<NamedExpressionType>(type) ) { - emitType(context, getType(context->astBuilder, namedType->declRef)); + emitType(context, getType(context->astBuilder, namedType->getDeclRef())); } else if( auto declRefType = dynamicCast<DeclRefType>(type) ) { - emitQualifiedName(context, declRefType->declRef); + emitQualifiedName(context, declRefType->getDeclRef()); } else if (auto arrType = dynamicCast<ArrayExpressionType>(type)) { @@ -220,19 +220,10 @@ namespace Slang emitSimpleIntVal(context, arrType->getElementCount()); emitType(context, arrType->getElementType()); } - else if( auto taggedUnionType = dynamicCast<TaggedUnionType>(type) ) - { - emitRaw(context, "u"); - for( auto caseType : taggedUnionType->caseTypes ) - { - emitType(context, caseType); - } - emitRaw(context, "U"); - } else if( auto thisType = dynamicCast<ThisType>(type) ) { emitRaw(context, "t"); - emitQualifiedName(context, thisType->interfaceDeclRef); + emitQualifiedName(context, thisType->getInterfaceDecl()); } else if (const auto errorType = dynamicCast<ErrorType>(type)) { @@ -300,50 +291,50 @@ namespace Slang // "depth" (how many outer generics) and "index" (which // parameter are they at the specified depth). emitRaw(context, "K"); - emitName(context, genericParamIntVal->declRef.getName()); + emitName(context, genericParamIntVal->getDeclRef().getName()); } else if( auto constantIntVal = dynamicCast<ConstantIntVal>(val) ) { // TODO: need to figure out what prefix/suffix is needed // to allow demangling later. emitRaw(context, "k"); - emit(context, (UInt) constantIntVal->value); + emit(context, (UInt) constantIntVal->getValue()); } else if (auto funcCallIntVal = dynamicCast<FuncCallIntVal>(val)) { emitRaw(context, "KC"); - emit(context, funcCallIntVal->args.getCount()); - emitName(context, funcCallIntVal->funcDeclRef.getName()); - for (Index i = 0; i < funcCallIntVal->args.getCount(); i++) - emitVal(context, funcCallIntVal->args[i]); + emit(context, funcCallIntVal->getArgs().getCount()); + emitName(context, funcCallIntVal->getFuncDeclRef().getName()); + for (Index i = 0; i < funcCallIntVal->getArgs().getCount(); i++) + emitVal(context, funcCallIntVal->getArgs()[i]); } else if (auto lookupIntVal = dynamicCast<WitnessLookupIntVal>(val)) { emitRaw(context, "KL"); - emitVal(context, lookupIntVal->witness); - emitName(context, lookupIntVal->key->getName()); + emitVal(context, lookupIntVal->getWitness()); + emitName(context, lookupIntVal->getKey()->getName()); } else if (const auto polynomialIntVal = dynamicCast<PolynomialIntVal>(val)) { emitRaw(context, "KX"); - emit(context, (UInt)polynomialIntVal->constantTerm); - emit(context, (UInt)polynomialIntVal->terms.getCount()); - for (auto term : polynomialIntVal->terms) + emit(context, (UInt)polynomialIntVal->getConstantTerm()); + emit(context, (UInt)polynomialIntVal->getTerms().getCount()); + for (auto term : polynomialIntVal->getTerms()) { - emit(context, (UInt)term->constFactor); - emit(context, (UInt)term->paramFactors.getCount()); - for (auto factor : term->paramFactors) + emit(context, (UInt)term->getConstFactor()); + emit(context, (UInt)term->getParamFactors().getCount()); + for (auto factor : term->getParamFactors()) { - emitVal(context, factor->param); - emit(context, (UInt)factor->power); + emitVal(context, factor->getParam()); + emit(context, (UInt)factor->getPower()); } } } else if (const auto typecastIntVal = dynamicCast<TypeCastIntVal>(val)) { emitRaw(context, "KK"); - emitVal(context, typecastIntVal->type); - emitVal(context, typecastIntVal->base); + emitVal(context, typecastIntVal->getType()); + emitVal(context, typecastIntVal->getBase()); } else { @@ -355,7 +346,7 @@ namespace Slang ManglingContext* context, DeclRef<Decl> declRef) { - auto parentDeclRef = declRef.getParent(context->astBuilder); + auto parentDeclRef = declRef.getParent(); auto parentGenericDeclRef = parentDeclRef.as<GenericDecl>(); if( parentDeclRef ) { @@ -423,14 +414,14 @@ namespace Slang // There are two cases here: either we have specializations // in place for the parent generic declaration, or we don't. - auto subst = findInnerMostGenericSubstitution(declRef.getSubst()); - if( subst && subst->getGenericDecl() == parentGenericDeclRef.getDecl()) + auto substArgs = tryGetGenericArguments(SubstitutionSet(declRef), parentGenericDeclRef.getDecl()); + if (substArgs.getCount()) { // This is the case where we *do* have substitutions. emitRaw(context, "G"); - UInt genericArgCount = subst->getArgs().getCount(); + UInt genericArgCount = substArgs.getCount(); emit(context, genericArgCount); - for (auto aa : subst->getArgs()) + for (auto aa : substArgs) { emitVal(context, aa); } @@ -441,7 +432,7 @@ namespace Slang // information about the parameters of the generic here. emitRaw(context, "g"); UInt genericParameterCount = 0; - for( auto mm : getMembers(context->astBuilder, parentGenericDeclRef) ) + for( auto mm : getMembers(context->astBuilder, parentGenericDeclRef.as<ContainerDecl>()) ) { if(mm.is<GenericTypeParamDecl>()) { @@ -569,7 +560,7 @@ namespace Slang // mangling the generic and the inner entity emitRaw(context, "G"); - SLANG_ASSERT(genericDecl.getSubst() == nullptr); + SLANG_ASSERT(SubstitutionSet(genericDecl).findGenericAppDeclRef() == nullptr); auto innerDecl = getInner(genericDecl); @@ -591,6 +582,7 @@ namespace Slang static String getMangledName(ASTBuilder* astBuilder, DeclRef<Decl> const& declRef) { + SLANG_AST_BUILDER_RAII(astBuilder); ManglingContext context(astBuilder); mangleName(&context, declRef); return context.sb.produceString(); @@ -598,11 +590,15 @@ namespace Slang String getMangledName(ASTBuilder* astBuilder, DeclRefBase* declRef) { + SLANG_AST_BUILDER_RAII(astBuilder); + return getMangledName(astBuilder, DeclRef<Decl>(declRef)); } String getMangledName(ASTBuilder* astBuilder, Decl* decl) { + SLANG_AST_BUILDER_RAII(astBuilder); + return getMangledName(astBuilder, makeDeclRef(decl)); } @@ -611,6 +607,7 @@ namespace Slang DeclRef<Decl> sub, DeclRef<Decl> sup) { + SLANG_AST_BUILDER_RAII(astBuilder); ManglingContext context(astBuilder); emitRaw(&context, "_SW"); emitQualifiedName(&context, sub); @@ -623,6 +620,7 @@ namespace Slang DeclRef<Decl> sub, Type* sup) { + SLANG_AST_BUILDER_RAII(astBuilder); // The mangled form for a witness that `sub` // conforms to `sup` will be named: // @@ -640,6 +638,7 @@ namespace Slang Type* sub, Type* sup) { + SLANG_AST_BUILDER_RAII(astBuilder); // The mangled form for a witness that `sub` // conforms to `sup` will be named: // @@ -654,6 +653,7 @@ namespace Slang String getMangledTypeName(ASTBuilder* astBuilder, Type* type) { + SLANG_AST_BUILDER_RAII(astBuilder); ManglingContext context(astBuilder); emitType(&context, type); return context.sb.produceString(); |
