From 0d206996cd68b9f08ae1b4d9da6f16293984302c Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 4 Feb 2019 12:11:18 -0500 Subject: Feature/casting tidyup (#822) * Use 'is' over 'as' where appropriate. * dynamic_cast -> dynamicCast * Replace 'dynamicCast' with 'as' where has no change in behavior/ambiguity. * Replace dynamicCast with as where doesn't change behavior/non ambiguous. --- source/slang/check.cpp | 90 +++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 45 deletions(-) (limited to 'source/slang/check.cpp') diff --git a/source/slang/check.cpp b/source/slang/check.cpp index d1294841c..cc245b5f4 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -35,9 +35,9 @@ namespace Slang // so (Java is an exception here, perhaps due to some // influence from the Scandanavian OOP tradition of Beta/gbeta). // - if(dynamic_cast(decl)) + if(as(decl)) return true; - if(dynamic_cast(decl)) + if(as(decl)) return true; // Things nested inside functions may have dependencies @@ -45,7 +45,7 @@ namespace Slang // be dealt with via "capture" so they are also effectively // `static` // - if(dynamic_cast(parentDecl)) + if(as(parentDecl)) return true; // Type constraint declarations are used in member-reference @@ -85,7 +85,7 @@ namespace Slang { // A global shader parameter must be declared at global (module) scope. // - if(!dynamic_cast(decl->ParentDecl)) return false; + if(!as(decl->ParentDecl)) return false; // A global variable marked `static` indicates a traditional // global variable (albeit one that is implicitly local to @@ -138,9 +138,9 @@ namespace Slang } else if (auto matrixType = as(typeIn)) { - if (auto elemCount1 = dynamic_cast(matrixType->getRowCount())) + if (auto elemCount1 = as(matrixType->getRowCount())) { - if (auto elemCount2 = dynamic_cast(matrixType->getColumnCount())) + if (auto elemCount2 = as(matrixType->getColumnCount())) { auto elemBasicType = as(matrixType->getElementType()); data.type = (unsigned char)elemBasicType->baseType; @@ -1638,7 +1638,7 @@ namespace Slang toMatrixType->getElementType(), toMatrixType->getColumnCount()); - if (auto constRowCount = dynamic_cast(toMatrixType->getRowCount())) + if (auto constRowCount = as(toMatrixType->getRowCount())) { rowCount = (UInt) constRowCount->value; } @@ -2400,7 +2400,7 @@ namespace Slang if (lookupResult.isValid()) { auto decl = lookupResult.item.declRef.getDecl(); - if (auto attributeDecl = dynamic_cast(decl)) + if (auto attributeDecl = as(decl)) { return attributeDecl; } @@ -3577,12 +3577,12 @@ namespace Slang // confirm that the type actually provides whatever // those clauses require. - if (auto interfaceDecl = dynamic_cast(decl)) + if (auto interfaceDecl = as(decl)) { // Don't check that an interface conforms to the // things it inherits from. } - else if (auto assocTypeDecl = dynamic_cast(decl)) + else if (auto assocTypeDecl = as(decl)) { // Don't check that an associated type decl conforms to the // things it inherits from. @@ -4083,11 +4083,11 @@ namespace Slang Decl* fstParam = fstParams[pp]; Decl* sndParam = sndParams[pp]; - if (auto fstTypeParam = dynamic_cast(fstParam)) + if (auto fstTypeParam = as(fstParam)) { - if (auto sndTypeParam = dynamic_cast(sndParam)) + if (auto sndTypeParam = as(sndParam)) { - // TODO: is there any validation that needs to be peformed here? + // TODO: is there any validation that needs to be performed here? } else { @@ -4095,9 +4095,9 @@ namespace Slang return false; } } - else if (auto fstValueParam = dynamic_cast(fstParam)) + else if (auto fstValueParam = as(fstParam)) { - if (auto sndValueParam = dynamic_cast(sndParam)) + if (auto sndValueParam = as(sndParam)) { // Need to check that the parameters have the same type. // @@ -4234,7 +4234,7 @@ namespace Slang // If this is a generic function (that is, its parent // declaration is a generic), then we need to look // for sibling declarations of the parent. - auto genericDecl = dynamic_cast(parentDecl); + auto genericDecl = as(parentDecl); if (genericDecl) { parentDecl = genericDecl->ParentDecl; @@ -4257,20 +4257,20 @@ namespace Slang auto prevDecl = pp; // Look through generics to the declaration underneath - auto prevGenericDecl = dynamic_cast(prevDecl); + auto prevGenericDecl = as(prevDecl); if (prevGenericDecl) prevDecl = prevGenericDecl->inner.Ptr(); // We only care about previously-declared functions // Note(tfoley): although we should really error out if the // name is already in use for something else, like a variable... - auto prevFuncDecl = dynamic_cast(prevDecl); + auto prevFuncDecl = as(prevDecl); if (!prevFuncDecl) continue; // If one declaration is a prefix/postfix operator, and the // other is not a matching operator, then don't consider these - // to be redeclarations. + // to be re-declarations. // // Note(tfoley): Any attempt to call such an operator using // ordinary function-call syntax (if we decided to allow it) @@ -4548,7 +4548,7 @@ namespace Slang for (UInt ii = outerStmtCount; ii > 0; --ii) { auto outerStmt = outerStmts[ii-1]; - auto found = dynamic_cast(outerStmt); + auto found = as(outerStmt); if (found) return found; } @@ -5013,19 +5013,19 @@ namespace Slang Expr* expr) { // Unwrap any "identity" expressions - while (auto parenExpr = dynamic_cast(expr)) + while (auto parenExpr = as(expr)) { expr = parenExpr->base; } // TODO(tfoley): more serious constant folding here - if (auto intLitExpr = dynamic_cast(expr)) + if (auto intLitExpr = as(expr)) { return GetIntVal(intLitExpr); } // it is possible that we are referring to a generic value param - if (auto declRefExpr = dynamic_cast(expr)) + if (auto declRefExpr = as(expr)) { auto declRef = declRefExpr->declRef; @@ -5104,13 +5104,13 @@ namespace Slang } } - if(auto castExpr = dynamic_cast(expr)) + if(auto castExpr = as(expr)) { auto val = TryConstantFoldExpr(castExpr->Arguments[0].Ptr()); if(val) return val; } - else if (auto invokeExpr = dynamic_cast(expr)) + else if (auto invokeExpr = as(expr)) { auto val = TryConstantFoldExpr(invokeExpr); if (val) @@ -5476,14 +5476,14 @@ namespace Slang // the grandparent. // auto parent = decl->ParentDecl; - auto genericParent = dynamic_cast(parent); + auto genericParent = as(parent); if (genericParent) { parent = genericParent->ParentDecl; } // Now look at the type of the parent (or grandparent). - if (auto aggTypeDecl = dynamic_cast(parent)) + if (auto aggTypeDecl = as(parent)) { // We are nested in an aggregate type declaration, // so the result type of the initializer will just @@ -5492,7 +5492,7 @@ namespace Slang getSession(), makeDeclRef(aggTypeDecl)); } - else if (auto extDecl = dynamic_cast(parent)) + else if (auto extDecl = as(parent)) { // We are nested inside an extension, so the result // type needs to be the type being extended. @@ -5582,7 +5582,7 @@ namespace Slang // its return type from the outer declaration, so we handle both // of these checks at the same place. auto parent = decl->ParentDecl; - if (auto parentSubscript = dynamic_cast(parent)) + if (auto parentSubscript = as(parent)) { decl->ReturnType = parentSubscript->ReturnType; } @@ -6783,7 +6783,7 @@ namespace Slang // We should have the existing arguments to the generic // handy, so that we can construct a substitution list. - RefPtr subst = candidate.subst.as(); + auto subst = candidate.subst.as(); SLANG_ASSERT(subst); subst->genericDecl = genericDeclRef.getDecl(); @@ -7200,7 +7200,7 @@ namespace Slang { auto parentDecl = decl->ParentDecl; if (!parentDecl) return nullptr; - auto parentGeneric = dynamic_cast(parentDecl); + auto parentGeneric = as(parentDecl); return parentGeneric; } @@ -7394,14 +7394,14 @@ namespace Slang { auto fstDeclRef = fstDeclRefType->declRef; - if (auto typeParamDecl = dynamic_cast(fstDeclRef.getDecl())) + if (auto typeParamDecl = as(fstDeclRef.getDecl())) return TryUnifyTypeParam(constraints, typeParamDecl, snd); if (auto sndDeclRefType = as(snd)) { auto sndDeclRef = sndDeclRefType->declRef; - if (auto typeParamDecl = dynamic_cast(sndDeclRef.getDecl())) + if (auto typeParamDecl = as(sndDeclRef.getDecl())) return TryUnifyTypeParam(constraints, typeParamDecl, fst); // can't be unified if they refer to different declarations. @@ -7447,7 +7447,7 @@ namespace Slang { auto fstDeclRef = fstDeclRefType->declRef; - if (auto typeParamDecl = dynamic_cast(fstDeclRef.getDecl())) + if (auto typeParamDecl = as(fstDeclRef.getDecl())) { if(typeParamDecl->ParentDecl == constraints.genericDecl ) return TryUnifyTypeParam(constraints, typeParamDecl, snd); @@ -7458,7 +7458,7 @@ namespace Slang { auto sndDeclRef = sndDeclRefType->declRef; - if (auto typeParamDecl = dynamic_cast(sndDeclRef.getDecl())) + if (auto typeParamDecl = as(sndDeclRef.getDecl())) { if(typeParamDecl->ParentDecl == constraints.genericDecl ) return TryUnifyTypeParam(constraints, typeParamDecl, fst); @@ -8236,7 +8236,7 @@ namespace Slang #if 0 // Debugging: ensure that we don't consider multiple declarations of the same operation - if (auto decl = dynamic_cast(candidate.item.declRef.decl)) + if (auto decl = as(candidate.item.declRef.decl)) { char buffer[1024]; sprintf_s(buffer, sizeof(buffer), "[this:%p, primary:%p, next:%p]", @@ -8451,7 +8451,7 @@ namespace Slang RefPtr CheckInvokeExprWithCheckedOperands(InvokeExpr *expr) { auto rs = ResolveInvoke(expr); - if (auto invoke = dynamic_cast(rs.Ptr())) + if (auto invoke = as(rs.Ptr())) { // if this is still an invoke expression, test arguments passed to inout/out parameter are LValues if(auto funcType = as(invoke->FunctionExpr->type)) @@ -9145,7 +9145,7 @@ namespace Slang for (auto ee = firstDeclWithName; ee; ee = ee->nextInContainerWithSameName) { // Is this declaration a function? - if (auto funcDecl = dynamic_cast(ee)) + if (auto funcDecl = as(ee)) { // Skip non-primary declarations, so that // we don't give an error when an entry @@ -9171,7 +9171,7 @@ namespace Slang // List all of the declarations that the user *might* mean for (auto ff = firstDeclWithName; ff; ff = ff->nextInContainerWithSameName) { - if (auto candidate = dynamic_cast(ff)) + if (auto candidate = as(ff)) { sink->diagnose(candidate, Diagnostics::entryPointCandidate, candidate->getName()); } @@ -9304,7 +9304,7 @@ namespace Slang for(auto ee = firstDeclWithName; ee; ee = ee->nextInContainerWithSameName) { // Is this declaration a function? - if (auto funcDecl = dynamic_cast(ee)) + if (auto funcDecl = as(ee)) { // Skip non-primary declarations, so that // we don't give an error when an entry @@ -9330,7 +9330,7 @@ namespace Slang // List all of the declarations that the user *might* mean for (auto ff = firstDeclWithName; ff; ff = ff->nextInContainerWithSameName) { - if (auto candidate = dynamic_cast(ff)) + if (auto candidate = as(ff)) { sink->diagnose(candidate, Diagnostics::entryPointCandidate, candidate->getName()); } @@ -9744,16 +9744,16 @@ namespace Slang isLValue = false; // Variables declared with `let` are always immutable. - if(as(varDeclRef.getDecl())) + if(varDeclRef.is()) isLValue = false; // Generic value parameters are always immutable - if(as(varDeclRef.getDecl())) + if(varDeclRef.is()) isLValue = false; // Function parameters declared in the "modern" style // are immutable unless they have an `out` or `inout` modifier. - if(as(varDeclRef.getDecl()) ) + if(varDeclRef.is()) { // Note: the `inout` modifier AST class inherits from // the class for the `out` modifier so that we can @@ -9885,7 +9885,7 @@ namespace Slang SubstitutionSet outerSubstSet) { auto dd = decl->ParentDecl; - if( auto genericDecl = dynamic_cast(dd) ) + if( auto genericDecl = as(dd) ) { // We don't want to specialize references to anything // other than the "inner" declaration itself. -- cgit v1.2.3