summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-conversion.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-06-05 18:20:09 -0400
committerGitHub <noreply@github.com>2020-06-05 18:20:09 -0400
commit43c146794aab638924d2ab838d10f8af2ebf02a7 (patch)
tree520eed8f2ae02c6953cf2aee7c87959a0008badc /source/slang/slang-check-conversion.cpp
parente3e1cf2045f14837cfecb14e252c0e1083787b93 (diff)
ASTNodes use MemoryArena (#1376)
* Add a ASTBuilder to a Module Only construct on valid ASTBuilder (was being called on nullptr on occassion) * Add nodes to ASTBuilder. * Compiles with RefPtr removed from AST node types. * Initialize all AST node pointer variables in headers to nullptr; * Initialize AST node variables as nullptr. Make ASTBuilder keep a ref on node types. Make SyntaxParseCallback returns a NodeBase * Don't release canonicalType on dtor (managed by ASTBuilder). * Give ASTBuilders a name and id, to help in debugging. For now destroy the session TypeCache, to stop it holding things released when the compile request destroys ASTBuilders. * Moved the TypeCheckingCache over to Linkage from Session. * NodeBase no longer derived from RefObject. * Only add/dtor nodes that need destruction. First pass compile on linux.
Diffstat (limited to 'source/slang/slang-check-conversion.cpp')
-rw-r--r--source/slang/slang-check-conversion.cpp98
1 files changed, 49 insertions, 49 deletions
diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp
index c4e809025..ba4a9b8d9 100644
--- a/source/slang/slang-check-conversion.cpp
+++ b/source/slang/slang-check-conversion.cpp
@@ -24,7 +24,7 @@ namespace Slang
}
bool SemanticsVisitor::isEffectivelyScalarForInitializerLists(
- RefPtr<Type> type)
+ Type* type)
{
if(as<ArrayExpressionType>(type)) return false;
if(as<VectorExpressionType>(type)) return false;
@@ -58,8 +58,8 @@ namespace Slang
}
bool SemanticsVisitor::shouldUseInitializerDirectly(
- RefPtr<Type> toType,
- RefPtr<Expr> fromExpr)
+ Type* toType,
+ Expr* fromExpr)
{
// A nested initializer list should always be used directly.
//
@@ -89,9 +89,9 @@ namespace Slang
}
bool SemanticsVisitor::_readValueFromInitializerList(
- RefPtr<Type> toType,
- RefPtr<Expr>* outToExpr,
- RefPtr<InitializerListExpr> fromInitializerListExpr,
+ Type* toType,
+ Expr** outToExpr,
+ InitializerListExpr* fromInitializerListExpr,
UInt &ioInitArgIndex)
{
// First, we will check if we have run out of arguments
@@ -152,9 +152,9 @@ namespace Slang
}
bool SemanticsVisitor::_readAggregateValueFromInitializerList(
- RefPtr<Type> inToType,
- RefPtr<Expr>* outToExpr,
- RefPtr<InitializerListExpr> fromInitializerListExpr,
+ Type* inToType,
+ Expr** outToExpr,
+ InitializerListExpr* fromInitializerListExpr,
UInt &ioArgIndex)
{
auto toType = inToType;
@@ -162,7 +162,7 @@ namespace Slang
// In the case where we need to build a result expression,
// we will collect the new arguments here
- List<RefPtr<Expr>> coercedArgs;
+ List<Expr*> coercedArgs;
if(isEffectivelyScalarForInitializerLists(toType))
{
@@ -215,7 +215,7 @@ namespace Slang
for(UInt ee = 0; ee < elementCount; ++ee)
{
- RefPtr<Expr> coercedArg;
+ Expr* coercedArg = nullptr;
bool argResult = _readValueFromInitializerList(
toElementType,
outToExpr ? &coercedArg : nullptr,
@@ -263,7 +263,7 @@ namespace Slang
for(UInt ee = 0; ee < elementCount; ++ee)
{
- RefPtr<Expr> coercedArg;
+ Expr* coercedArg = nullptr;
bool argResult = _readValueFromInitializerList(
toElementType,
outToExpr ? &coercedArg : nullptr,
@@ -289,7 +289,7 @@ namespace Slang
UInt elementCount = 0;
while(ioArgIndex < argCount)
{
- RefPtr<Expr> coercedArg;
+ Expr* coercedArg = nullptr;
bool argResult = _readValueFromInitializerList(
toElementType,
outToExpr ? &coercedArg : nullptr,
@@ -352,7 +352,7 @@ namespace Slang
for(UInt rr = 0; rr < rowCount; ++rr)
{
- RefPtr<Expr> coercedArg;
+ Expr* coercedArg = nullptr;
bool argResult = _readValueFromInitializerList(
toRowType,
outToExpr ? &coercedArg : nullptr,
@@ -380,7 +380,7 @@ namespace Slang
//
for(auto fieldDeclRef : getMembersOfType<VarDecl>(toStructDeclRef, MemberFilterStyle::Instance))
{
- RefPtr<Expr> coercedArg;
+ Expr* coercedArg = nullptr;
bool argResult = _readValueFromInitializerList(
getType(m_astBuilder, fieldDeclRef),
outToExpr ? &coercedArg : nullptr,
@@ -429,9 +429,9 @@ namespace Slang
}
bool SemanticsVisitor::_coerceInitializerList(
- RefPtr<Type> toType,
- RefPtr<Expr>* outToExpr,
- RefPtr<InitializerListExpr> fromInitializerListExpr)
+ Type* toType,
+ Expr** outToExpr,
+ InitializerListExpr* fromInitializerListExpr)
{
UInt argCount = fromInitializerListExpr->args.getCount();
UInt argIndex = 0;
@@ -454,9 +454,9 @@ namespace Slang
}
bool SemanticsVisitor::_failedCoercion(
- RefPtr<Type> toType,
- RefPtr<Expr>* outToExpr,
- RefPtr<Expr> fromExpr)
+ Type* toType,
+ Expr** outToExpr,
+ Expr* fromExpr)
{
if(outToExpr)
{
@@ -478,10 +478,10 @@ namespace Slang
}
bool SemanticsVisitor::_coerce(
- RefPtr<Type> toType,
- RefPtr<Expr>* outToExpr,
- RefPtr<Type> fromType,
- RefPtr<Expr> fromExpr,
+ Type* toType,
+ Expr** outToExpr,
+ Type* fromType,
+ Expr* fromExpr,
ConversionCost* outCost)
{
// An important and easy case is when the "to" and "from" types are equal.
@@ -571,7 +571,7 @@ namespace Slang
//
ConversionCost subCost = kConversionCost_None;
- RefPtr<DerefExpr> derefExpr;
+ DerefExpr* derefExpr = nullptr;
if(outToExpr)
{
derefExpr = m_astBuilder->create<DerefExpr>();
@@ -754,8 +754,8 @@ namespace Slang
}
bool SemanticsVisitor::canCoerce(
- RefPtr<Type> toType,
- RefPtr<Type> fromType,
+ Type* toType,
+ Type* fromType,
ConversionCost* outCost)
{
// As an optimization, we will maintain a cache of conversion results
@@ -764,11 +764,11 @@ namespace Slang
bool shouldAddToCache = false;
ConversionCost cost;
- TypeCheckingCache* typeCheckingCache = getSession()->getTypeCheckingCache();
+ TypeCheckingCache* typeCheckingCache = getLinkage()->getTypeCheckingCache();
BasicTypeKeyPair cacheKey;
- cacheKey.type1 = makeBasicTypeKey(toType.Ptr());
- cacheKey.type2 = makeBasicTypeKey(fromType.Ptr());
+ cacheKey.type1 = makeBasicTypeKey(toType);
+ cacheKey.type2 = makeBasicTypeKey(fromType);
if( cacheKey.isValid())
{
@@ -811,16 +811,16 @@ namespace Slang
return rs;
}
- RefPtr<TypeCastExpr> SemanticsVisitor::createImplicitCastExpr()
+ TypeCastExpr* SemanticsVisitor::createImplicitCastExpr()
{
return m_astBuilder->create<ImplicitCastExpr>();
}
- RefPtr<Expr> SemanticsVisitor::CreateImplicitCastExpr(
- RefPtr<Type> toType,
- RefPtr<Expr> fromExpr)
+ Expr* SemanticsVisitor::CreateImplicitCastExpr(
+ Type* toType,
+ Expr* fromExpr)
{
- RefPtr<TypeCastExpr> castExpr = createImplicitCastExpr();
+ TypeCastExpr* castExpr = createImplicitCastExpr();
auto typeType = m_astBuilder->getTypeType(toType);
@@ -835,12 +835,12 @@ namespace Slang
return castExpr;
}
- RefPtr<Expr> SemanticsVisitor::createCastToSuperTypeExpr(
- RefPtr<Type> toType,
- RefPtr<Expr> fromExpr,
- RefPtr<Val> witness)
+ Expr* SemanticsVisitor::createCastToSuperTypeExpr(
+ Type* toType,
+ Expr* fromExpr,
+ Val* witness)
{
- RefPtr<CastToSuperTypeExpr> expr = m_astBuilder->create<CastToSuperTypeExpr>();
+ CastToSuperTypeExpr* expr = m_astBuilder->create<CastToSuperTypeExpr>();
expr->loc = fromExpr->loc;
expr->type = QualType(toType);
expr->valueArg = fromExpr;
@@ -848,16 +848,16 @@ namespace Slang
return expr;
}
- RefPtr<Expr> SemanticsVisitor::coerce(
- RefPtr<Type> toType,
- RefPtr<Expr> fromExpr)
+ Expr* SemanticsVisitor::coerce(
+ Type* toType,
+ Expr* fromExpr)
{
- RefPtr<Expr> expr;
+ Expr* expr = nullptr;
if (!_coerce(
toType,
&expr,
- fromExpr->type.Ptr(),
- fromExpr.Ptr(),
+ fromExpr->type,
+ fromExpr,
nullptr))
{
// Note(tfoley): We don't call `CreateErrorExpr` here, because that would
@@ -872,8 +872,8 @@ namespace Slang
}
bool SemanticsVisitor::canConvertImplicitly(
- RefPtr<Type> toType,
- RefPtr<Type> fromType)
+ Type* toType,
+ Type* fromType)
{
// Can we convert at all?
ConversionCost conversionCost;