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/lower-to-ir.cpp | 62 ++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'source/slang/lower-to-ir.cpp') diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index f88a44e53..9cfb857e8 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -389,7 +389,7 @@ ModuleDecl* findModuleDecl(Decl* decl) { for (auto dd = decl; dd; dd = dd->ParentDecl) { - if (auto moduleDecl = dynamic_cast(dd)) + if (auto moduleDecl = as(dd)) return moduleDecl; } return nullptr; @@ -1704,7 +1704,7 @@ static String getNameForNameHint( return String(); - if(auto varDecl = dynamic_cast(decl)) + if(auto varDecl = as(decl)) { // For an ordinary local variable, global variable, // parameter, or field, we will just use the name @@ -1722,7 +1722,7 @@ static String getNameForNameHint( auto parentDecl = decl->ParentDecl; // Skip past a generic parent, if we are a declaration nested in a generic. - if(auto genericParentDecl = dynamic_cast(parentDecl)) + if(auto genericParentDecl = as(parentDecl)) parentDecl = genericParentDecl->ParentDecl; auto parentName = getNameForNameHint(context, parentDecl); @@ -2423,7 +2423,7 @@ struct ExprLoweringVisitorBase : ExprVisitor // In such a case we should be careful to not statically // resolve things. // - if(auto callableDecl = dynamic_cast(declRefExpr->declRef.getDecl())) + if(auto callableDecl = as(declRefExpr->declRef.getDecl())) { // Okay, the declaration is directly callable, so we can continue. } @@ -3380,20 +3380,20 @@ struct StmtLoweringVisitor : StmtVisitor // enclosing `switch`. // // For now we will assume that any `case` and `default` - // statements need to be direclty nested under the `switch`, + // statements need to be directly nested under the `switch`, // and so we can find them with a simpler walk. Stmt* stmt = inStmt; // Unwrap any surrounding `{ ... }` so we can look // at the statement inside. - while(auto blockStmt = dynamic_cast(stmt)) + while(auto blockStmt = as(stmt)) { stmt = blockStmt->body; continue; } - if(auto seqStmt = dynamic_cast(stmt)) + if(auto seqStmt = as(stmt)) { // Walk through teh children and process each. for(auto childStmt : seqStmt->stmts) @@ -3401,7 +3401,7 @@ struct StmtLoweringVisitor : StmtVisitor lowerSwitchCases(childStmt, info); } } - else if(auto caseStmt = dynamic_cast(stmt)) + else if(auto caseStmt = as(stmt)) { // A full `case` statement has a value we need // to test against. It is expected to be a @@ -3429,7 +3429,7 @@ struct StmtLoweringVisitor : StmtVisitor info->cases.Add(caseVal); info->cases.Add(label); } - else if(auto defaultStmt = dynamic_cast(stmt)) + else if(auto defaultStmt = as(stmt)) { auto label = getLabelForCase(info); @@ -3438,7 +3438,7 @@ struct StmtLoweringVisitor : StmtVisitor info->defaultLabel = label; } - else if(auto emptyStmt = dynamic_cast(stmt)) + else if(auto emptyStmt = as(stmt)) { // Special-case empty statements so they don't // mess up our "trivial fall-through" optimization. @@ -3446,7 +3446,7 @@ struct StmtLoweringVisitor : StmtVisitor else { // We have an ordinary statement, that needs to get - // emitted to the currrent case block. + // emitted to the current case block. if(!info->currentCaseLabel) { // It possible in full C/C++ to have statements @@ -4217,7 +4217,7 @@ struct DeclLoweringVisitor : DeclVisitor // then we need to identify the type being extended. // RefPtr subType; - if (auto extParentDecl = dynamic_cast(parentDecl)) + if (auto extParentDecl = as(parentDecl)) { subType = extParentDecl->targetType.type; } @@ -4324,12 +4324,12 @@ struct DeclLoweringVisitor : DeclVisitor bool isGlobalVarDecl(VarDecl* decl) { auto parent = decl->ParentDecl; - if (dynamic_cast(parent)) + if (as(parent)) { // Variable declared at global scope? -> Global. return true; } - else if(dynamic_cast(parent)) + else if(as(parent)) { if(decl->HasModifier()) { @@ -4344,7 +4344,7 @@ struct DeclLoweringVisitor : DeclVisitor bool isMemberVarDecl(VarDecl* decl) { auto parent = decl->ParentDecl; - if (dynamic_cast(parent)) + if (as(parent)) { // A variable declared inside of an aggregate type declaration is a member. return true; @@ -4466,7 +4466,7 @@ struct DeclLoweringVisitor : DeclVisitor // set correctly, so we can't just scan up and look // for a function in the parent chain... auto parent = decl->ParentDecl; - if( dynamic_cast(parent) ) + if( as(parent) ) { return true; } @@ -4538,7 +4538,7 @@ struct DeclLoweringVisitor : DeclVisitor for(auto pp = decl->ParentDecl; pp; pp = pp->ParentDecl) { - if(auto genericAncestor = dynamic_cast(pp)) + if(auto genericAncestor = as(pp)) { return defaultSpecializeOuterGeneric(parentVal, type, genericAncestor); } @@ -5235,11 +5235,11 @@ struct DeclLoweringVisitor : DeclVisitor direction = kParameterDirection_InOut; } - if( auto aggTypeDecl = dynamic_cast(parentDecl) ) + if( auto aggTypeDecl = as(parentDecl) ) { addThisParameter(direction, aggTypeDecl, ioParameterLists); } - else if( auto extensionDecl = dynamic_cast(parentDecl) ) + else if( auto extensionDecl = as(parentDecl) ) { addThisParameter(direction, extensionDecl->targetType, ioParameterLists); } @@ -5249,7 +5249,7 @@ struct DeclLoweringVisitor : DeclVisitor // Once we've added any parameters based on parent declarations, // we can see if this declaration itself introduces parameters. // - if( auto callableDecl = dynamic_cast(decl) ) + if( auto callableDecl = as(decl) ) { // Don't collect parameters from the outer scope if // we are in a `static` context. @@ -5360,7 +5360,7 @@ struct DeclLoweringVisitor : DeclVisitor { for(auto pp = decl->ParentDecl; pp; pp = pp->ParentDecl) { - if(auto genericAncestor = dynamic_cast(pp)) + if(auto genericAncestor = as(pp)) { return emitOuterGeneric(subContext, genericAncestor, leafDecl); } @@ -5467,13 +5467,13 @@ struct DeclLoweringVisitor : DeclVisitor // // We compute a declaration to use for looking up the return type here: CallableDecl* declForReturnType = decl; - if (auto accessorDecl = dynamic_cast(decl)) + if (auto accessorDecl = as(decl)) { // We are some kind of accessor, so the parent declaration should // know the correct return type to expose. // auto parentDecl = accessorDecl->ParentDecl; - if (auto subscriptDecl = dynamic_cast(parentDecl)) + if (auto subscriptDecl = as(parentDecl)) { declForReturnType = subscriptDecl; } @@ -5529,7 +5529,7 @@ struct DeclLoweringVisitor : DeclVisitor auto irResultType = lowerType(subContext, declForReturnType->ReturnType); - if (auto setterDecl = dynamic_cast(decl)) + if (auto setterDecl = as(decl)) { // We are lowering a "setter" accessor inside a subscript // declaration, which means we don't want to *return* the @@ -5544,7 +5544,7 @@ struct DeclLoweringVisitor : DeclVisitor irResultType = subBuilder->getVoidType(); } - if( auto refAccessorDecl = dynamic_cast(decl) ) + if( auto refAccessorDecl = as(decl) ) { // A `ref` accessor needs to return a *pointer* to the value // being accessed, rather than a simple value. @@ -5678,7 +5678,7 @@ struct DeclLoweringVisitor : DeclVisitor } } - if (auto setterDecl = dynamic_cast(decl)) + if (auto setterDecl = as(decl)) { // Add the IR parameter for the new value IRType* irParamType = irResultType; @@ -5836,12 +5836,12 @@ struct DeclLoweringVisitor : DeclVisitor // TODO: Need to be careful about how this is approached, // to avoid emitting a bunch of extra definitions in the IR. - auto primaryFuncDecl = dynamic_cast(primaryDecl); + auto primaryFuncDecl = as(primaryDecl); SLANG_ASSERT(primaryFuncDecl); LoweredValInfo result = lowerFuncDecl(primaryFuncDecl); for (auto dd = primaryDecl->nextDecl; dd; dd = dd->nextDecl) { - auto funcDecl = dynamic_cast(dd); + auto funcDecl = as(dd); SLANG_ASSERT(funcDecl); lowerFuncDecl(funcDecl); } @@ -5915,11 +5915,11 @@ IRInst* lowerSubstitutionArg( IRGenContext* context, Val* val) { - if (auto type = dynamic_cast(val)) + if (auto type = dynamicCast(val)) { return lowerType(context, type); } - else if (auto declaredSubtypeWitness = dynamic_cast(val)) + else if (auto declaredSubtypeWitness = as(val)) { // We need to look up the IR-level representation of the witness (which will be a witness table). auto irWitnessTable = getSimpleVal( @@ -6161,7 +6161,7 @@ static void ensureAllDeclsRec( // Aggregate types are the main case where we can emit an outer declaration // and not the stuff nested inside of it. // - if(auto containerDecl = dynamic_cast(decl)) + if(auto containerDecl = as(decl)) { for (auto memberDecl : containerDecl->Members) { -- cgit v1.2.3