@@ -988,10 +988,10 @@ void IRGenerator::convertFunction(const ASTNode& f) {
988988 std::vector<const FunctionDeclaration*> functions;
989989 switch (entry->fKind ) {
990990 case Symbol::kUnresolvedFunction_Kind :
991- functions = ((UnresolvedFunction*) entry)-> fFunctions ;
991+ functions = entry-> as <UnresolvedFunction>(). fFunctions ;
992992 break ;
993993 case Symbol::kFunctionDeclaration_Kind :
994- functions.push_back (( FunctionDeclaration*) entry );
994+ functions.push_back (&entry-> as < FunctionDeclaration>() );
995995 break ;
996996 default :
997997 fErrors .error (f.fOffset , " symbol '" + fd.fName + " ' was already defined" );
@@ -1243,13 +1243,13 @@ const Type* IRGenerator::convertType(const ASTNode& type) {
12431243 const Symbol* result = (*fSymbolTable )[td.fName ];
12441244 if (result && result->fKind == Symbol::kType_Kind ) {
12451245 if (td.fIsNullable ) {
1246- if (((Type&) * result) == *fContext .fFragmentProcessor_Type ) {
1246+ if (result-> as <Type>( ) == *fContext .fFragmentProcessor_Type ) {
12471247 if (type.begin () != type.end ()) {
12481248 fErrors .error (type.fOffset , " type '" + td.fName + " ' may not be used in "
12491249 " an array" );
12501250 }
12511251 result = fSymbolTable ->takeOwnershipOfSymbol (std::make_unique<Type>(
1252- String (result->fName ) + " ?" , Type::kNullable_Kind , ( const Type&)*result ));
1252+ String (result->fName ) + " ?" , Type::kNullable_Kind , result-> as < Type>() ));
12531253 } else {
12541254 fErrors .error (type.fOffset , " type '" + td.fName + " ' may not be nullable" );
12551255 }
@@ -1262,9 +1262,9 @@ const Type* IRGenerator::convertType(const ASTNode& type) {
12621262 }
12631263 name += " ]" ;
12641264 result = fSymbolTable ->takeOwnershipOfSymbol (std::make_unique<Type>(
1265- name, Type::kArray_Kind , ( const Type&)*result , size ? size.getInt () : 0 ));
1265+ name, Type::kArray_Kind , result-> as < Type>() , size ? size.getInt () : 0 ));
12661266 }
1267- return ( const Type*) result ;
1267+ return &result-> as < Type>() ;
12681268 }
12691269 fErrors .error (type.fOffset , " unknown type '" + td.fName + " '" );
12701270 return nullptr ;
@@ -1317,16 +1317,16 @@ std::unique_ptr<Expression> IRGenerator::convertIdentifier(const ASTNode& identi
13171317 switch (result->fKind ) {
13181318 case Symbol::kFunctionDeclaration_Kind : {
13191319 std::vector<const FunctionDeclaration*> f = {
1320- ( const FunctionDeclaration*) result
1320+ &result-> as < FunctionDeclaration>()
13211321 };
13221322 return std::make_unique<FunctionReference>(fContext , identifier.fOffset , f);
13231323 }
13241324 case Symbol::kUnresolvedFunction_Kind : {
1325- const UnresolvedFunction* f = ( const UnresolvedFunction*) result ;
1325+ const UnresolvedFunction* f = &result-> as < UnresolvedFunction>() ;
13261326 return std::make_unique<FunctionReference>(fContext , identifier.fOffset , f->fFunctions );
13271327 }
13281328 case Symbol::kVariable_Kind : {
1329- const Variable* var = ( const Variable*) result ;
1329+ const Variable* var = &result-> as < Variable>() ;
13301330 switch (var->fModifiers .fLayout .fBuiltin ) {
13311331 case SK_WIDTH_BUILTIN:
13321332 fInputs .fRTWidth = true ;
@@ -1373,7 +1373,7 @@ std::unique_ptr<Expression> IRGenerator::convertIdentifier(const ASTNode& identi
13731373 VariableReference::kRead_RefKind );
13741374 }
13751375 case Symbol::kField_Kind : {
1376- const Field* field = ( const Field*) result ;
1376+ const Field* field = &result-> as < Field>() ;
13771377 VariableReference* base = new VariableReference (identifier.fOffset , field->fOwner ,
13781378 VariableReference::kRead_RefKind );
13791379 return std::unique_ptr<Expression>(new FieldAccess (
@@ -1382,11 +1382,11 @@ std::unique_ptr<Expression> IRGenerator::convertIdentifier(const ASTNode& identi
13821382 FieldAccess::kAnonymousInterfaceBlock_OwnerKind ));
13831383 }
13841384 case Symbol::kType_Kind : {
1385- const Type* t = ( const Type*) result ;
1385+ const Type* t = &result-> as < Type>() ;
13861386 return std::make_unique<TypeReference>(fContext , identifier.fOffset , *t);
13871387 }
13881388 case Symbol::kExternal_Kind : {
1389- const ExternalValue* r = ( const ExternalValue*) result ;
1389+ const ExternalValue* r = &result-> as < ExternalValue>() ;
13901390 return std::make_unique<ExternalValueReference>(identifier.fOffset , r);
13911391 }
13921392 default :
@@ -2500,7 +2500,7 @@ std::unique_ptr<Expression> IRGenerator::call(int offset,
25002500 ((TypeReference&) *functionValue).fValue ,
25012501 std::move (arguments));
25022502 case Expression::kExternalValue_Kind : {
2503- const ExternalValue* v = ((ExternalValueReference&) * functionValue).fValue ;
2503+ const ExternalValue* v = functionValue-> as <ExternalValueReference>( ).fValue ;
25042504 if (!v->canCall ()) {
25052505 fErrors .error (offset, " this external value is not a function" );
25062506 return nullptr ;
@@ -2809,7 +2809,7 @@ std::unique_ptr<Expression> IRGenerator::convertIndex(std::unique_ptr<Expression
28092809std::unique_ptr<Expression> IRGenerator::convertField (std::unique_ptr<Expression> base,
28102810 StringFragment field) {
28112811 if (base->fKind == Expression::kExternalValue_Kind ) {
2812- const ExternalValue& ev = *((ExternalValueReference&) * base).fValue ;
2812+ const ExternalValue& ev = *base-> as <ExternalValueReference>( ).fValue ;
28132813 ExternalValue* result = ev.getChild (String (field).c_str ());
28142814 if (!result) {
28152815 fErrors .error (base->fOffset , " external value does not have a child named '" + field +
0 commit comments