remove some dyncast calls (#15488)

This commit is contained in:
Walter Bright 2023-08-01 02:48:34 -07:00 committed by GitHub
parent a4e9bf514a
commit 04f46ff87d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 15 deletions

View file

@ -626,7 +626,7 @@ extern (C++) final class TupleDeclaration : Declaration
for (size_t i = 0; i < objects.length; i++) for (size_t i = 0; i < objects.length; i++)
{ {
RootObject o = (*objects)[i]; RootObject o = (*objects)[i];
if (o.dyncast() != DYNCAST.type) if (!o.isType())
{ {
//printf("\tnot[%d], %p, %d\n", i, o, o.dyncast()); //printf("\tnot[%d], %p, %d\n", i, o, o.dyncast());
return null; return null;

View file

@ -7706,7 +7706,7 @@ private void removeHookTraceImpl(ref CallExp ce, ref FuncDeclaration fd)
// Get the Hook from the second template parameter // Get the Hook from the second template parameter
TemplateInstance templateInstance = fd.parent.isTemplateInstance; TemplateInstance templateInstance = fd.parent.isTemplateInstance;
RootObject hook = (*templateInstance.tiargs)[1]; RootObject hook = (*templateInstance.tiargs)[1];
assert(hook.dyncast() == DYNCAST.dsymbol, "Expected _d_HookTraceImpl's second template parameter to be an alias to the hook!"); assert(hook.isDsymbol(), "Expected _d_HookTraceImpl's second template parameter to be an alias to the hook!");
fd = (cast(Dsymbol)hook).isFuncDeclaration; fd = (cast(Dsymbol)hook).isFuncDeclaration;
// Remove the first three trace parameters // Remove the first three trace parameters

View file

@ -168,7 +168,7 @@ extern (C++) struct Scope
sc.minst = _module; sc.minst = _module;
sc.scopesym = new ScopeDsymbol(); sc.scopesym = new ScopeDsymbol();
sc.scopesym.symtab = new DsymbolTable(); sc.scopesym.symtab = new DsymbolTable();
sc.eSink = eSink; sc.eSink = eSink;
// Add top level package as member of this global scope // Add top level package as member of this global scope
Dsymbol m = _module; Dsymbol m = _module;
while (m.parent) while (m.parent)

View file

@ -353,9 +353,9 @@ extern (C++) class Dsymbol : ASTNode
{ {
if (this == o) if (this == o)
return true; return true;
if (o.dyncast() != DYNCAST.dsymbol) const s = o.isDsymbol();
if (!s)
return false; return false;
auto s = cast(Dsymbol)o;
// Overload sets don't have an ident // Overload sets don't have an ident
// Function-local declarations may have identical names // Function-local declarations may have identical names
// if they are declared in different scopes // if they are declared in different scopes

View file

@ -4708,9 +4708,9 @@ void errorSupplementalInferredAttr(FuncDeclaration fd, int maxDepth, bool deprec
s.arg0 ? s.arg0.toChars() : "", s.arg1 ? s.arg1.toChars() : "", s.arg2 ? s.arg2.toChars() : ""); s.arg0 ? s.arg0.toChars() : "", s.arg1 ? s.arg1.toChars() : "", s.arg2 ? s.arg2.toChars() : "");
} }
} }
else if (s.arg0.dyncast() == DYNCAST.dsymbol) else if (auto sa = s.arg0.isDsymbol())
{ {
if (FuncDeclaration fd2 = (cast(Dsymbol) s.arg0).isFuncDeclaration()) if (FuncDeclaration fd2 = sa.isFuncDeclaration())
{ {
if (maxDepth > 0) if (maxDepth > 0)
{ {

View file

@ -19,6 +19,7 @@ import dmd.aggregate;
import dmd.astenums; import dmd.astenums;
import dmd.declaration; import dmd.declaration;
import dmd.dscope; import dmd.dscope;
import dmd.dtemplate : isDsymbol;
import dmd.errors; import dmd.errors;
import dmd.expression; import dmd.expression;
import dmd.func; import dmd.func;
@ -263,6 +264,7 @@ private FuncDeclaration stripHookTraceImpl(FuncDeclaration fd)
// Get the Hook from the second template parameter // Get the Hook from the second template parameter
auto templateInstance = fd.parent.isTemplateInstance; auto templateInstance = fd.parent.isTemplateInstance;
RootObject hook = (*templateInstance.tiargs)[1]; RootObject hook = (*templateInstance.tiargs)[1];
assert(hook.dyncast() == DYNCAST.dsymbol, "Expected _d_HookTraceImpl's second template parameter to be an alias to the hook!"); Dsymbol s = hook.isDsymbol();
return (cast(Dsymbol)hook).isFuncDeclaration; assert(s, "Expected _d_HookTraceImpl's second template parameter to be an alias to the hook!");
return s.isFuncDeclaration;
} }

View file

@ -530,12 +530,10 @@ extern(C++) Type typeSemantic(Type type, const ref Loc loc, Scope* sc)
} }
RootObject o = (*tup.objects)[cast(size_t)d]; RootObject o = (*tup.objects)[cast(size_t)d];
if (o.dyncast() != DYNCAST.type) if (auto tt = o.isType())
{ return tt.addMod(mtype.mod);
.error(loc, "`%s` is not a type", mtype.toChars()); .error(loc, "`%s` is not a type", mtype.toChars());
return error(); return error();
}
return (cast(Type)o).addMod(mtype.mod);
} }
if (t && t.ty == Terror) if (t && t.ty == Terror)