Changeset 0bd3faf for src/ResolvExpr
- Timestamp:
- Nov 13, 2023, 1:40:12 PM (2 years ago)
- Branches:
- master
- Children:
- 6ea85b22
- Parents:
- 25f2798
- Location:
- src/ResolvExpr
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AdjustExprType.cc
r25f2798 r0bd3faf 23 23 24 24 namespace { 25 class AdjustExprType _newfinal : public ast::WithShortCircuiting {25 class AdjustExprType final : public ast::WithShortCircuiting { 26 26 const ast::SymbolTable & symtab; 27 27 public: 28 28 const ast::TypeEnvironment & tenv; 29 29 30 AdjustExprType _new( const ast::TypeEnvironment & e, const ast::SymbolTable & syms )30 AdjustExprType( const ast::TypeEnvironment & e, const ast::SymbolTable & syms ) 31 31 : symtab( syms ), tenv( e ) {} 32 32 … … 75 75 const ast::Type * type, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab 76 76 ) { 77 ast::Pass<AdjustExprType _new> adjuster{ env, symtab };77 ast::Pass<AdjustExprType> adjuster{ env, symtab }; 78 78 return type->accept( adjuster ); 79 79 } -
src/ResolvExpr/AdjustExprType.hpp
r25f2798 r0bd3faf 16 16 #pragma once 17 17 18 class Type;19 namespace SymTab {20 class Indexer;21 }22 18 namespace ast { 23 19 class SymbolTable; … … 27 23 28 24 namespace ResolvExpr { 29 30 class TypeEnvironment;31 32 /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function33 void adjustExprType( Type *& type, const TypeEnvironment & env, const SymTab::Indexer & indexer );34 35 /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function using empty TypeEnvironment and Indexer.36 void adjustExprType( Type *& type );37 38 template< typename ForwardIterator >39 void adjustExprTypeList( ForwardIterator begin, ForwardIterator end, const TypeEnvironment & env, const SymTab::Indexer & indexer ) {40 while ( begin != end ) {41 adjustExprType( *begin++, env, indexer );42 } // while43 }44 25 45 26 /// Replaces array types with equivalent pointer, -
src/ResolvExpr/CandidateFinder.cpp
r25f2798 r0bd3faf 61 61 namespace { 62 62 /// First index is which argument, second is which alternative, third is which exploded element 63 using ExplodedArgs _new= std::deque< std::vector< ExplodedArg > >;63 using ExplodedArgs = std::deque< std::vector< ExplodedArg > >; 64 64 65 65 /// Returns a list of alternatives with the minimum cost in the given list … … 255 255 256 256 /// Gets the list of exploded candidates for this pack 257 const ExplodedArg & getExpl( const ExplodedArgs _new& args ) const {257 const ExplodedArg & getExpl( const ExplodedArgs & args ) const { 258 258 return args[ nextArg-1 ][ explAlt ]; 259 259 } … … 281 281 bool instantiateArgument( 282 282 const CodeLocation & location, 283 const ast::Type * paramType, const ast::Init * init, const ExplodedArgs _new& args,283 const ast::Type * paramType, const ast::Init * init, const ExplodedArgs & args, 284 284 std::vector< ArgPack > & results, std::size_t & genStart, const ast::SymbolTable & symtab, 285 285 unsigned nTuples = 0 … … 618 618 const CodeLocation & location, 619 619 const CandidateRef & func, const ast::FunctionType * funcType, 620 const ExplodedArgs _new& args, CandidateList & out );620 const ExplodedArgs & args, CandidateList & out ); 621 621 622 622 /// Adds implicit struct-conversions to the alternative list … … 737 737 const CodeLocation & location, 738 738 const CandidateRef & func, const ast::FunctionType * funcType, 739 const ExplodedArgs _new& args, CandidateList & out739 const ExplodedArgs & args, CandidateList & out 740 740 ) { 741 741 ast::OpenVarSet funcOpen; … … 997 997 998 998 // pre-explode arguments 999 ExplodedArgs _newargExpansions;999 ExplodedArgs argExpansions; 1000 1000 for ( const CandidateFinder & args : argCandidates ) { 1001 1001 argExpansions.emplace_back(); -
src/ResolvExpr/CastCost.cc
r25f2798 r0bd3faf 26 26 #include "ResolvExpr/ConversionCost.h" // for conversionCost 27 27 #include "ResolvExpr/PtrsCastable.hpp" // for ptrsCastable 28 #include "ResolvExpr/typeops.h" // for ptrsCastable29 28 #include "ResolvExpr/Unify.h" // for typesCompatibleIgnoreQualifiers 30 29 … … 38 37 39 38 namespace { 40 struct CastCost _new : public ConversionCost_new{41 using ConversionCost _new::previsit;42 using ConversionCost _new::postvisit;39 struct CastCost : public ConversionCost { 40 using ConversionCost::previsit; 41 using ConversionCost::postvisit; 43 42 44 CastCost _new(43 CastCost( 45 44 const ast::Type * dst, bool srcIsLvalue, const ast::SymbolTable & symtab, 46 45 const ast::TypeEnvironment & env, CostCalculation costFunc ) 47 : ConversionCost _new( dst, srcIsLvalue, symtab, env, costFunc ) {}46 : ConversionCost( dst, srcIsLvalue, symtab, env, costFunc ) {} 48 47 49 48 void postvisit( const ast::BasicType * basicType ) { … … 85 84 }; 86 85 87 #warning For overload resolution between the two versions.88 int localPtrsCastable(const ast::Type * t1, const ast::Type * t2,89 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ) {90 return ptrsCastable( t1, t2, symtab, env );91 }92 Cost localCastCost(93 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,94 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env95 ) { return castCost( src, dst, srcIsLvalue, symtab, env ); }96 86 } // anonymous namespace 97 87 … … 136 126 } else if ( auto refType = dynamic_cast< const ast::ReferenceType * >( dst ) ) { 137 127 PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; ) 138 #warning cast on ptrsCastable artifact of having two functions, remove when port done139 128 return convertToReferenceCost( 140 src, refType, srcIsLvalue, symtab, env, localPtrsCastable );129 src, refType, srcIsLvalue, symtab, env, ptrsCastable ); 141 130 } else { 142 #warning cast on castCost artifact of having two functions, remove when port done 143 ast::Pass< CastCost_new > converter( 144 dst, srcIsLvalue, symtab, env, localCastCost ); 131 ast::Pass< CastCost > converter( 132 dst, srcIsLvalue, symtab, env, castCost ); 145 133 src->accept( converter ); 146 134 return converter.core.cost; -
src/ResolvExpr/CastCost.hpp
r25f2798 r0bd3faf 18 18 #include "ResolvExpr/Cost.h" // for Cost 19 19 20 class Type;21 namespace SymTab {22 class Indexer;23 }24 20 namespace ast { 25 21 class SymbolTable; … … 30 26 namespace ResolvExpr { 31 27 32 class TypeEnvironment;33 34 Cost castCost(35 const Type * src, const Type * dest, bool srcIsLvalue,36 const SymTab::Indexer & indexer, const TypeEnvironment & env );37 28 Cost castCost( 38 29 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue, -
src/ResolvExpr/CommonType.cc
r25f2798 r0bd3faf 343 343 ); 344 344 345 class CommonType _newfinal : public ast::WithShortCircuiting {345 class CommonType final : public ast::WithShortCircuiting { 346 346 const ast::Type * type2; 347 347 WidenMode widen; … … 354 354 ast::ptr< ast::Type > result; 355 355 356 CommonType _new(356 CommonType( 357 357 const ast::Type * t2, WidenMode w, 358 358 ast::TypeEnvironment & env, const ast::OpenVarSet & o, … … 388 388 result = enumDecl->base.get(); 389 389 } else { 390 #warning remove casts when `commonTypes` moved to new AST391 390 ast::BasicType::Kind kind = commonTypes[ basic->kind ][ ast::BasicType::SignedInt ]; 392 391 if ( … … 739 738 }; 740 739 741 // size_t CommonType _new::traceId = Stats::Heap::new_stacktrace_id("CommonType_new");740 // size_t CommonType::traceId = Stats::Heap::new_stacktrace_id("CommonType"); 742 741 namespace { 743 742 ast::ptr< ast::Type > handleReference( … … 811 810 } 812 811 // otherwise both are reference types of the same depth and this is handled by the visitor 813 ast::Pass<CommonType _new> visitor{ type2, widen, env, open, need, have };812 ast::Pass<CommonType> visitor{ type2, widen, env, open, need, have }; 814 813 type1->accept( visitor ); 815 814 // ast::ptr< ast::Type > result = visitor.core.result; -
src/ResolvExpr/ConversionCost.cc
r25f2798 r0bd3faf 153 153 154 154 namespace { 155 # warning For overload resolution between the two versions.156 155 int localPtrsAssignable(const ast::Type * t1, const ast::Type * t2, 157 156 const ast::SymbolTable &, const ast::TypeEnvironment & env ) { 158 157 return ptrsAssignable( t1, t2, env ); 159 158 } 160 Cost localConversionCost(161 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,162 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env163 ) { return conversionCost( src, dst, srcIsLvalue, symtab, env ); }164 159 } 165 160 … … 191 186 return convertToReferenceCost( src, refType, srcIsLvalue, symtab, env, localPtrsAssignable ); 192 187 } else { 193 return ast::Pass<ConversionCost _new>::read( src, dst, srcIsLvalue, symtab, env, localConversionCost );188 return ast::Pass<ConversionCost>::read( src, dst, srcIsLvalue, symtab, env, conversionCost ); 194 189 } 195 190 } … … 232 227 } 233 228 } else { 234 return ast::Pass<ConversionCost _new>::read( src, dst, srcIsLvalue, symtab, env, localConversionCost );229 return ast::Pass<ConversionCost>::read( src, dst, srcIsLvalue, symtab, env, conversionCost ); 235 230 } 236 231 } else { … … 264 259 } 265 260 266 void ConversionCost _new::postvisit( const ast::VoidType * voidType ) {261 void ConversionCost::postvisit( const ast::VoidType * voidType ) { 267 262 (void)voidType; 268 263 cost = Cost::infinity; 269 264 } 270 265 271 void ConversionCost _new::conversionCostFromBasicToBasic( const ast::BasicType * src, const ast::BasicType* dest ) {266 void ConversionCost::conversionCostFromBasicToBasic( const ast::BasicType * src, const ast::BasicType* dest ) { 272 267 int tableResult = costMatrix[ src->kind ][ dest->kind ]; 273 268 if ( tableResult == -1 ) { … … 280 275 } 281 276 282 void ConversionCost _new::postvisit( const ast::BasicType * basicType ) {277 void ConversionCost::postvisit( const ast::BasicType * basicType ) { 283 278 if ( const ast::BasicType * dstAsBasic = dynamic_cast< const ast::BasicType * >( dst ) ) { 284 279 conversionCostFromBasicToBasic( basicType, dstAsBasic ); … … 286 281 const ast::EnumDecl * enumDecl = enumInst->base.get(); 287 282 if ( enumDecl->isTyped && !enumDecl->base.get() ) { 288 cost = Cost::infinity; 283 cost = Cost::infinity; 289 284 } else if ( const ast::Type * enumType = enumDecl->base.get() ) { 290 285 if ( const ast::BasicType * enumTypeAsBasic = dynamic_cast<const ast::BasicType *>(enumType) ) { … … 299 294 } 300 295 301 void ConversionCost _new::postvisit( const ast::PointerType * pointerType ) {296 void ConversionCost::postvisit( const ast::PointerType * pointerType ) { 302 297 if ( const ast::PointerType * dstAsPtr = dynamic_cast< const ast::PointerType * >( dst ) ) { 303 298 ast::CV::Qualifiers tq1 = pointerType->base->qualifiers; … … 345 340 } 346 341 347 void ConversionCost _new::postvisit( const ast::ArrayType * arrayType ) {342 void ConversionCost::postvisit( const ast::ArrayType * arrayType ) { 348 343 (void)arrayType; 349 344 } 350 345 351 void ConversionCost _new::postvisit( const ast::ReferenceType * refType ) {346 void ConversionCost::postvisit( const ast::ReferenceType * refType ) { 352 347 assert( nullptr == dynamic_cast< const ast::ReferenceType * >( dst ) ); 353 348 … … 367 362 } 368 363 369 void ConversionCost _new::postvisit( const ast::FunctionType * functionType ) {364 void ConversionCost::postvisit( const ast::FunctionType * functionType ) { 370 365 (void)functionType; 371 366 } 372 367 373 void ConversionCost _new::postvisit( const ast::EnumInstType * enumInstType ) {368 void ConversionCost::postvisit( const ast::EnumInstType * enumInstType ) { 374 369 const ast::EnumDecl * baseEnum = enumInstType->base; 375 370 if ( const ast::Type * baseType = baseEnum->base ) { … … 384 379 } 385 380 386 void ConversionCost _new::postvisit( const ast::TraitInstType * traitInstType ) {381 void ConversionCost::postvisit( const ast::TraitInstType * traitInstType ) { 387 382 (void)traitInstType; 388 383 } 389 384 390 void ConversionCost _new::postvisit( const ast::TypeInstType * typeInstType ) {385 void ConversionCost::postvisit( const ast::TypeInstType * typeInstType ) { 391 386 if ( const ast::EqvClass * eqv = env.lookup( *typeInstType ) ) { 392 387 cost = costCalc( eqv->bound, dst, srcIsLvalue, symtab, env ); … … 405 400 } 406 401 407 void ConversionCost _new::postvisit( const ast::TupleType * tupleType ) {402 void ConversionCost::postvisit( const ast::TupleType * tupleType ) { 408 403 Cost c = Cost::zero; 409 404 if ( const ast::TupleType * dstAsTuple = dynamic_cast< const ast::TupleType * >( dst ) ) { … … 427 422 } 428 423 429 void ConversionCost _new::postvisit( const ast::VarArgsType * varArgsType ) {424 void ConversionCost::postvisit( const ast::VarArgsType * varArgsType ) { 430 425 (void)varArgsType; 431 426 if ( dynamic_cast< const ast::VarArgsType * >( dst ) ) { … … 434 429 } 435 430 436 void ConversionCost _new::postvisit( const ast::ZeroType * zeroType ) {431 void ConversionCost::postvisit( const ast::ZeroType * zeroType ) { 437 432 (void)zeroType; 438 433 if ( dynamic_cast< const ast::ZeroType * >( dst ) ) { … … 461 456 } 462 457 463 void ConversionCost _new::postvisit( const ast::OneType * oneType ) {458 void ConversionCost::postvisit( const ast::OneType * oneType ) { 464 459 (void)oneType; 465 460 if ( dynamic_cast< const ast::OneType * >( dst ) ) { 466 461 cost = Cost::zero; 467 462 } else if ( const ast::BasicType * dstAsBasic = 468 dynamic_cast< const ast::BasicType * >( dst ) ) { 463 dynamic_cast< const ast::BasicType * >( dst ) ) { 469 464 int tableResult = costMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ]; 470 465 if ( -1 == tableResult ) { … … 475 470 cost.incSign( signMatrix[ ast::BasicType::SignedInt ][ dstAsBasic->kind ] ); 476 471 } 477 478 // cost = Cost::zero; 479 } 480 } 481 // size_t ConversionCost_new::traceId = Stats::Heap::new_stacktrace_id("ConversionCost"); 472 } 473 } 474 475 // size_t ConversionCost::traceId = Stats::Heap::new_stacktrace_id("ConversionCost"); 482 476 483 477 } // namespace ResolvExpr -
src/ResolvExpr/ConversionCost.h
r25f2798 r0bd3faf 23 23 #include "AST/Pass.hpp" // for WithShortCircuiting 24 24 25 namespace SymTab {26 class Indexer;27 } // namespace SymTab28 29 25 namespace ResolvExpr { 30 class TypeEnvironment;31 26 32 27 // Some function pointer types, differ in return type. … … 44 39 PtrsCalculation func ); 45 40 46 #warning when the old ConversionCost is removed, get ride of the _new suffix. 47 class ConversionCost_new : public ast::WithShortCircuiting { 41 class ConversionCost : public ast::WithShortCircuiting { 48 42 protected: 49 43 const ast::Type * dst; … … 57 51 Cost result() { return cost; } 58 52 59 ConversionCost _new( const ast::Type * dst, bool srcIsLvalue, const ast::SymbolTable & symtab,53 ConversionCost( const ast::Type * dst, bool srcIsLvalue, const ast::SymbolTable & symtab, 60 54 const ast::TypeEnvironment & env, CostCalculation costCalc ) : 61 55 dst( dst ), srcIsLvalue( srcIsLvalue ), symtab( symtab ), env( env ), -
src/ResolvExpr/FindOpenVars.cc
r25f2798 r0bd3faf 25 25 26 26 namespace { 27 struct FindOpenVars _newfinal : public ast::WithGuards {27 struct FindOpenVars final : public ast::WithGuards { 28 28 ast::OpenVarSet & open; 29 29 ast::OpenVarSet & closed; … … 33 33 bool nextIsOpen; 34 34 35 FindOpenVars _new(35 FindOpenVars( 36 36 ast::OpenVarSet & o, ast::OpenVarSet & c, ast::AssertionSet & n, 37 37 ast::AssertionSet & h, ast::TypeEnvironment & env, FirstMode firstIsOpen ) … … 73 73 const ast::Type * type, ast::OpenVarSet & open, ast::OpenVarSet & closed, 74 74 ast::AssertionSet & need, ast::AssertionSet & have, ast::TypeEnvironment & env, FirstMode firstIsOpen ) { 75 ast::Pass< FindOpenVars _new> finder{ open, closed, need, have, env, firstIsOpen };75 ast::Pass< FindOpenVars > finder{ open, closed, need, have, env, firstIsOpen }; 76 76 type->accept( finder ); 77 77 -
src/ResolvExpr/PolyCost.cc
r25f2798 r0bd3faf 21 21 namespace ResolvExpr { 22 22 23 // TODO: When the old PolyCost is torn out get rid of the _new suffix. 24 class PolyCost_new { 23 class PolyCost { 25 24 const ast::SymbolTable &symtab; 26 25 public: … … 28 27 const ast::TypeEnvironment &env_; 29 28 30 PolyCost _new( const ast::SymbolTable & symtab, const ast::TypeEnvironment & env )29 PolyCost( const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ) 31 30 : symtab( symtab ), result( 0 ), env_( env ) {} 32 31 … … 49 48 const ast::Type * type, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env 50 49 ) { 51 ast::Pass<PolyCost _new> costing( symtab, env );50 ast::Pass<PolyCost> costing( symtab, env ); 52 51 type->accept( costing ); 53 52 return (costing.core.result > 0) ? 1 : 0; -
src/ResolvExpr/PolyCost.hpp
r25f2798 r0bd3faf 16 16 #pragma once 17 17 18 class Type;19 namespace SymTab {20 class Indexer;21 }22 18 namespace ast { 23 19 class SymbolTable; … … 28 24 namespace ResolvExpr { 29 25 30 class TypeEnvironment;31 32 int polyCost( Type * type,33 const TypeEnvironment & env, const SymTab::Indexer & indexer );34 26 int polyCost( const ast::Type * type, 35 27 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ); -
src/ResolvExpr/PtrsAssignable.cc
r25f2798 r0bd3faf 22 22 namespace ResolvExpr { 23 23 24 // TODO: Get rid of the `_new` suffix when the old version is removed. 25 struct PtrsAssignable_new : public ast::WithShortCircuiting { 24 struct PtrsAssignable : public ast::WithShortCircuiting { 26 25 const ast::Type * dst; 27 26 const ast::TypeEnvironment & typeEnv; 28 27 int result; 29 28 30 PtrsAssignable _new( const ast::Type * dst, const ast::TypeEnvironment & env ) :29 PtrsAssignable( const ast::Type * dst, const ast::TypeEnvironment & env ) : 31 30 dst( dst ), typeEnv( env ), result( 0 ) {} 32 31 33 void previsit( Type * ) { visit_children = false; }32 void previsit( ast::Type * ) { visit_children = false; } 34 33 35 34 void postvisit( const ast::EnumInstType * ) { … … 63 62 return -1; 64 63 } else { 65 ast::Pass<PtrsAssignable _new> visitor( dst, env );64 ast::Pass<PtrsAssignable> visitor( dst, env ); 66 65 src->accept( visitor ); 67 66 return visitor.core.result; -
src/ResolvExpr/PtrsAssignable.hpp
r25f2798 r0bd3faf 16 16 #pragma once 17 17 18 class Type;19 18 namespace ast { 20 19 class Type; … … 24 23 namespace ResolvExpr { 25 24 26 class TypeEnvironment;27 28 int ptrsAssignable( const Type * src, const Type * dest,29 const TypeEnvironment & env );30 25 int ptrsAssignable( const ast::Type * src, const ast::Type * dst, 31 26 const ast::TypeEnvironment & env ); -
src/ResolvExpr/PtrsCastable.cc
r25f2798 r0bd3faf 55 55 } 56 56 57 class PtrsCastable _new: public ast::WithShortCircuiting {57 class PtrsCastable : public ast::WithShortCircuiting { 58 58 const ast::Type * dst; 59 59 const ast::TypeEnvironment & env; … … 62 62 int result; 63 63 64 PtrsCastable _new(64 PtrsCastable( 65 65 const ast::Type * d, const ast::TypeEnvironment & e, const ast::SymbolTable & syms ) 66 66 : dst( d ), env( e ), symtab( syms ), result( 0 ) {} … … 149 149 return objectCast( src, env, symtab ); 150 150 } else { 151 return ast::Pass<PtrsCastable _new>::read( src, dst, env, symtab );151 return ast::Pass<PtrsCastable>::read( src, dst, env, symtab ); 152 152 } 153 153 } -
src/ResolvExpr/PtrsCastable.hpp
r25f2798 r0bd3faf 16 16 #pragma once 17 17 18 class Type;19 namespace SymTab {20 class Indexer;21 }22 18 namespace ast { 23 19 class SymbolTable; … … 28 24 namespace ResolvExpr { 29 25 30 class TypeEnvironment;31 32 int ptrsCastable(33 const Type * src, const Type * dst,34 const TypeEnvironment & env, const SymTab::Indexer & indexer );35 26 int ptrsCastable( 36 27 const ast::Type * src, const ast::Type * dst, -
src/ResolvExpr/RenameVars.cc
r25f2798 r0bd3faf 101 101 RenamingData renaming; 102 102 103 struct RenameVars _new: public ast::PureVisitor /*: public ast::WithForallSubstitutor*/ {103 struct RenameVars final : public ast::PureVisitor /*: public ast::WithForallSubstitutor*/ { 104 104 RenameMode mode; 105 105 … … 132 132 133 133 const ast::Type * renameTyVars( const ast::Type * t, RenameMode mode, bool reset ) { 134 ast::Pass<RenameVars _new> renamer;134 ast::Pass<RenameVars> renamer; 135 135 renamer.core.mode = mode; 136 136 if (mode == GEN_USAGE && reset) { -
src/ResolvExpr/ResolveTypeof.cc
r25f2798 r0bd3faf 33 33 34 34 namespace { 35 struct ResolveTypeof _new: public ast::WithShortCircuiting {35 struct ResolveTypeof : public ast::WithShortCircuiting { 36 36 const ResolveContext & context; 37 37 38 ResolveTypeof _new( const ResolveContext & context ) :38 ResolveTypeof( const ResolveContext & context ) : 39 39 context( context ) {} 40 40 … … 78 78 79 79 const ast::Type * resolveTypeof( const ast::Type * type , const ResolveContext & context ) { 80 ast::Pass< ResolveTypeof _new> mutator( context );80 ast::Pass< ResolveTypeof > mutator( context ); 81 81 return type->accept( mutator ); 82 82 } -
src/ResolvExpr/ResolveTypeof.h
r25f2798 r0bd3faf 16 16 #pragma once 17 17 18 class Type;19 namespace SymTab {20 class Indexer;21 } // namespace SymTab22 18 namespace ast { 23 19 class Type; … … 28 24 struct ResolveContext; 29 25 30 Type *resolveTypeof( Type*, const SymTab::Indexer &indexer );31 26 const ast::Type * resolveTypeof( const ast::Type *, const ResolveContext & ); 32 27 const ast::Type * fixArrayType( const ast::Type *, const ResolveContext & ); 33 28 const ast::ObjectDecl * fixObjectType( const ast::ObjectDecl * decl , const ResolveContext & ); 34 const ast::ObjectDecl * fixObjectInit( const ast::ObjectDecl * decl , const ResolveContext & );29 const ast::ObjectDecl * fixObjectInit( const ast::ObjectDecl * decl , const ResolveContext & ); 35 30 } // namespace ResolvExpr 36 31 -
src/ResolvExpr/Resolver.cc
r25f2798 r0bd3faf 62 62 namespace { 63 63 /// Finds deleted expressions in an expression tree 64 struct DeleteFinder _new final : public ast::WithShortCircuiting, public ast::WithVisitorRef<DeleteFinder_new> {64 struct DeleteFinder final : public ast::WithShortCircuiting, public ast::WithVisitorRef<DeleteFinder> { 65 65 const ast::DeletedExpr * result = nullptr; 66 66 … … 80 80 }; 81 81 82 struct ResolveDesignators _newfinal : public ast::WithShortCircuiting {82 struct ResolveDesignators final : public ast::WithShortCircuiting { 83 83 ResolveContext& context; 84 84 bool result = false; 85 85 86 ResolveDesignators _new( ResolveContext& _context ): context{_context} {};86 ResolveDesignators( ResolveContext& _context ): context{_context} {}; 87 87 88 88 void previsit( const ast::Node * ) { … … 113 113 /// Check if this expression is or includes a deleted expression 114 114 const ast::DeletedExpr * findDeletedExpr( const ast::Expr * expr ) { 115 return ast::Pass<DeleteFinder _new>::read( expr );115 return ast::Pass<DeleteFinder>::read( expr ); 116 116 } 117 117 … … 203 203 204 204 /// Strips extraneous casts out of an expression 205 struct StripCasts _newfinal {205 struct StripCasts final { 206 206 const ast::Expr * postvisit( const ast::CastExpr * castExpr ) { 207 207 if ( … … 217 217 218 218 static void strip( ast::ptr< ast::Expr > & expr ) { 219 ast::Pass< StripCasts _new> stripper;219 ast::Pass< StripCasts > stripper; 220 220 expr = expr->accept( stripper ); 221 221 } … … 251 251 expr.get_and_mutate()->env = std::move( newenv ); 252 252 // remove unncecessary casts 253 StripCasts _new::strip( expr );253 StripCasts::strip( expr ); 254 254 } 255 255 … … 368 368 } 369 369 370 class Resolver _newfinal370 class Resolver final 371 371 : public ast::WithSymbolTable, public ast::WithGuards, 372 public ast::WithVisitorRef<Resolver _new>, public ast::WithShortCircuiting,372 public ast::WithVisitorRef<Resolver>, public ast::WithShortCircuiting, 373 373 public ast::WithStmtsToAdd<> { 374 374 … … 376 376 ast::CurrentObject currentObject; 377 377 // for work previously in GenInit 378 static InitTweak::ManagedTypes _newmanagedTypes;378 static InitTweak::ManagedTypes managedTypes; 379 379 ResolveContext context; 380 380 … … 383 383 public: 384 384 static size_t traceId; 385 Resolver _new( const ast::TranslationGlobal & global ) :385 Resolver( const ast::TranslationGlobal & global ) : 386 386 ast::WithSymbolTable(ast::SymbolTable::ErrorDetection::ValidateOnAdd), 387 387 context{ symtab, global } {} 388 Resolver _new( const ResolveContext & context ) :388 Resolver( const ResolveContext & context ) : 389 389 ast::WithSymbolTable{ context.symtab }, 390 390 context{ symtab, context.global } {} … … 427 427 bool on_error(ast::ptr<ast::Decl> & decl); 428 428 }; 429 // size_t Resolver _new::traceId = Stats::Heap::new_stacktrace_id("Resolver");430 431 InitTweak::ManagedTypes _new Resolver_new::managedTypes;429 // size_t Resolver::traceId = Stats::Heap::new_stacktrace_id("Resolver"); 430 431 InitTweak::ManagedTypes Resolver::managedTypes; 432 432 433 433 void resolve( ast::TranslationUnit& translationUnit ) { 434 ast::Pass< Resolver _new>::run( translationUnit, translationUnit.global );434 ast::Pass< Resolver >::run( translationUnit, translationUnit.global ); 435 435 } 436 436 … … 439 439 ) { 440 440 assert( ctorInit ); 441 ast::Pass< Resolver _new> resolver( context );441 ast::Pass< Resolver > resolver( context ); 442 442 return ctorInit->accept( resolver ); 443 443 } … … 447 447 ) { 448 448 assert( stmtExpr ); 449 ast::Pass< Resolver _new> resolver( context );449 ast::Pass< Resolver > resolver( context ); 450 450 auto ret = mutate(stmtExpr->accept(resolver)); 451 451 strict_dynamic_cast< ast::StmtExpr * >( ret )->computeResult(); … … 489 489 } 490 490 491 const ast::FunctionDecl * Resolver _new::previsit( const ast::FunctionDecl * functionDecl ) {491 const ast::FunctionDecl * Resolver::previsit( const ast::FunctionDecl * functionDecl ) { 492 492 GuardValue( functionReturn ); 493 493 … … 563 563 } 564 564 565 const ast::FunctionDecl * Resolver _new::postvisit( const ast::FunctionDecl * functionDecl ) {565 const ast::FunctionDecl * Resolver::postvisit( const ast::FunctionDecl * functionDecl ) { 566 566 // default value expressions have an environment which shouldn't be there and trips up 567 567 // later passes. … … 591 591 } 592 592 593 const ast::ObjectDecl * Resolver _new::previsit( const ast::ObjectDecl * objectDecl ) {593 const ast::ObjectDecl * Resolver::previsit( const ast::ObjectDecl * objectDecl ) { 594 594 // To handle initialization of routine pointers [e.g. int (*fp)(int) = foo()], 595 595 // class-variable `initContext` is changed multiple times because the LHS is analyzed … … 630 630 // constructed objects cannot be designated 631 631 if ( InitTweak::isDesignated( mutDecl->init ) ) { 632 ast::Pass<ResolveDesignators _new> res( context );632 ast::Pass<ResolveDesignators> res( context ); 633 633 maybe_accept( mutDecl->init.get(), res ); 634 634 if ( !res.core.result ) { … … 650 650 } 651 651 652 void Resolver _new::previsit( const ast::AggregateDecl * _aggDecl ) {652 void Resolver::previsit( const ast::AggregateDecl * _aggDecl ) { 653 653 auto aggDecl = mutate(_aggDecl); 654 654 assertf(aggDecl == _aggDecl, "type declarations must be unique"); … … 662 662 } 663 663 664 void Resolver _new::previsit( const ast::StructDecl * structDecl ) {664 void Resolver::previsit( const ast::StructDecl * structDecl ) { 665 665 previsit(static_cast<const ast::AggregateDecl *>(structDecl)); 666 666 managedTypes.handleStruct(structDecl); 667 667 } 668 668 669 void Resolver _new::previsit( const ast::EnumDecl * ) {669 void Resolver::previsit( const ast::EnumDecl * ) { 670 670 // in case we decide to allow nested enums 671 671 GuardValue( inEnumDecl ); … … 674 674 } 675 675 676 const ast::StaticAssertDecl * Resolver _new::previsit(676 const ast::StaticAssertDecl * Resolver::previsit( 677 677 const ast::StaticAssertDecl * assertDecl 678 678 ) { … … 694 694 } 695 695 696 const ast::ArrayType * Resolver _new::previsit( const ast::ArrayType * at ) {696 const ast::ArrayType * Resolver::previsit( const ast::ArrayType * at ) { 697 697 return handlePtrType( at, context ); 698 698 } 699 699 700 const ast::PointerType * Resolver _new::previsit( const ast::PointerType * pt ) {700 const ast::PointerType * Resolver::previsit( const ast::PointerType * pt ) { 701 701 return handlePtrType( pt, context ); 702 702 } 703 703 704 const ast::ExprStmt * Resolver _new::previsit( const ast::ExprStmt * exprStmt ) {704 const ast::ExprStmt * Resolver::previsit( const ast::ExprStmt * exprStmt ) { 705 705 visit_children = false; 706 706 assertf( exprStmt->expr, "ExprStmt has null expression in resolver" ); … … 710 710 } 711 711 712 const ast::AsmExpr * Resolver _new::previsit( const ast::AsmExpr * asmExpr ) {712 const ast::AsmExpr * Resolver::previsit( const ast::AsmExpr * asmExpr ) { 713 713 visit_children = false; 714 714 … … 719 719 } 720 720 721 const ast::AsmStmt * Resolver _new::previsit( const ast::AsmStmt * asmStmt ) {721 const ast::AsmStmt * Resolver::previsit( const ast::AsmStmt * asmStmt ) { 722 722 visitor->maybe_accept( asmStmt, &ast::AsmStmt::input ); 723 723 visitor->maybe_accept( asmStmt, &ast::AsmStmt::output ); … … 726 726 } 727 727 728 const ast::IfStmt * Resolver _new::previsit( const ast::IfStmt * ifStmt ) {728 const ast::IfStmt * Resolver::previsit( const ast::IfStmt * ifStmt ) { 729 729 return ast::mutate_field( 730 730 ifStmt, &ast::IfStmt::cond, findIntegralExpression( ifStmt->cond, context ) ); 731 731 } 732 732 733 const ast::WhileDoStmt * Resolver _new::previsit( const ast::WhileDoStmt * whileDoStmt ) {733 const ast::WhileDoStmt * Resolver::previsit( const ast::WhileDoStmt * whileDoStmt ) { 734 734 return ast::mutate_field( 735 735 whileDoStmt, &ast::WhileDoStmt::cond, findIntegralExpression( whileDoStmt->cond, context ) ); 736 736 } 737 737 738 const ast::ForStmt * Resolver _new::previsit( const ast::ForStmt * forStmt ) {738 const ast::ForStmt * Resolver::previsit( const ast::ForStmt * forStmt ) { 739 739 if ( forStmt->cond ) { 740 740 forStmt = ast::mutate_field( … … 750 750 } 751 751 752 const ast::SwitchStmt * Resolver _new::previsit( const ast::SwitchStmt * switchStmt ) {752 const ast::SwitchStmt * Resolver::previsit( const ast::SwitchStmt * switchStmt ) { 753 753 GuardValue( currentObject ); 754 754 switchStmt = ast::mutate_field( … … 759 759 } 760 760 761 const ast::CaseClause * Resolver _new::previsit( const ast::CaseClause * caseStmt ) {761 const ast::CaseClause * Resolver::previsit( const ast::CaseClause * caseStmt ) { 762 762 if ( caseStmt->cond ) { 763 763 std::deque< ast::InitAlternative > initAlts = currentObject.getOptions(); … … 780 780 } 781 781 782 const ast::BranchStmt * Resolver _new::previsit( const ast::BranchStmt * branchStmt ) {782 const ast::BranchStmt * Resolver::previsit( const ast::BranchStmt * branchStmt ) { 783 783 visit_children = false; 784 784 // must resolve the argument of a computed goto … … 793 793 } 794 794 795 const ast::ReturnStmt * Resolver _new::previsit( const ast::ReturnStmt * returnStmt ) {795 const ast::ReturnStmt * Resolver::previsit( const ast::ReturnStmt * returnStmt ) { 796 796 visit_children = false; 797 797 if ( returnStmt->expr ) { … … 803 803 } 804 804 805 const ast::ThrowStmt * Resolver _new::previsit( const ast::ThrowStmt * throwStmt ) {805 const ast::ThrowStmt * Resolver::previsit( const ast::ThrowStmt * throwStmt ) { 806 806 visit_children = false; 807 807 if ( throwStmt->expr ) { … … 818 818 } 819 819 820 const ast::CatchClause * Resolver _new::previsit( const ast::CatchClause * catchClause ) {820 const ast::CatchClause * Resolver::previsit( const ast::CatchClause * catchClause ) { 821 821 // Until we are very sure this invarent (ifs that move between passes have then) 822 822 // holds, check it. This allows a check for when to decode the mangling. … … 834 834 } 835 835 836 const ast::CatchClause * Resolver _new::postvisit( const ast::CatchClause * catchClause ) {836 const ast::CatchClause * Resolver::postvisit( const ast::CatchClause * catchClause ) { 837 837 // Decode the catchStmt so everything is stored properly. 838 838 const ast::IfStmt * ifStmt = catchClause->body.as<ast::IfStmt>(); … … 849 849 } 850 850 851 const ast::WaitForStmt * Resolver _new::previsit( const ast::WaitForStmt * stmt ) {851 const ast::WaitForStmt * Resolver::previsit( const ast::WaitForStmt * stmt ) { 852 852 visit_children = false; 853 853 … … 1114 1114 } 1115 1115 1116 const ast::WithStmt * Resolver _new::previsit( const ast::WithStmt * withStmt ) {1116 const ast::WithStmt * Resolver::previsit( const ast::WithStmt * withStmt ) { 1117 1117 auto mutStmt = mutate(withStmt); 1118 1118 resolveWithExprs(mutStmt->exprs, stmtsToAddBefore); … … 1120 1120 } 1121 1121 1122 void Resolver _new::resolveWithExprs(std::vector<ast::ptr<ast::Expr>> & exprs, std::list<ast::ptr<ast::Stmt>> & stmtsToAdd) {1122 void Resolver::resolveWithExprs(std::vector<ast::ptr<ast::Expr>> & exprs, std::list<ast::ptr<ast::Stmt>> & stmtsToAdd) { 1123 1123 for (auto & expr : exprs) { 1124 1124 // only struct- and union-typed expressions are viable candidates … … 1146 1146 1147 1147 1148 const ast::SingleInit * Resolver _new::previsit( const ast::SingleInit * singleInit ) {1148 const ast::SingleInit * Resolver::previsit( const ast::SingleInit * singleInit ) { 1149 1149 visit_children = false; 1150 1150 // resolve initialization using the possibilities as determined by the `currentObject` … … 1195 1195 } 1196 1196 1197 const ast::ListInit * Resolver _new::previsit( const ast::ListInit * listInit ) {1197 const ast::ListInit * Resolver::previsit( const ast::ListInit * listInit ) { 1198 1198 // move cursor into brace-enclosed initializer-list 1199 1199 currentObject.enterListInit( listInit->location ); … … 1218 1218 } 1219 1219 1220 const ast::ConstructorInit * Resolver _new::previsit( const ast::ConstructorInit * ctorInit ) {1220 const ast::ConstructorInit * Resolver::previsit( const ast::ConstructorInit * ctorInit ) { 1221 1221 visitor->maybe_accept( ctorInit, &ast::ConstructorInit::ctor ); 1222 1222 visitor->maybe_accept( ctorInit, &ast::ConstructorInit::dtor ); … … 1240 1240 1241 1241 // suppress error on autogen functions and mark invalid autogen as deleted. 1242 bool Resolver _new::on_error(ast::ptr<ast::Decl> & decl) {1242 bool Resolver::on_error(ast::ptr<ast::Decl> & decl) { 1243 1243 if (auto functionDecl = decl.as<ast::FunctionDecl>()) { 1244 1244 // xxx - can intrinsic gen ever fail? -
src/ResolvExpr/Resolver.h
r25f2798 r0bd3faf 16 16 #pragma once 17 17 18 #include <list> // for list19 20 18 #include "AST/Node.hpp" // for ptr 21 22 class ConstructorInit;23 class Declaration;24 class Expression;25 class DeletedExpr;26 class StmtExpr;27 class Type;28 namespace SymTab {29 class Indexer;30 } // namespace SymTab31 19 32 20 namespace ast { … … 45 33 46 34 namespace ResolvExpr { 47 /// Checks types and binds syntactic constructs to typed representations48 void resolve( std::list< Declaration * > translationUnit );49 void resolveDecl( Declaration *, const SymTab::Indexer & indexer );50 Expression *resolveInVoidContext( Expression * expr, const SymTab::Indexer & indexer );51 void findVoidExpression( Expression *& untyped, const SymTab::Indexer & indexer );52 void findSingleExpression( Expression *& untyped, const SymTab::Indexer & indexer );53 void findSingleExpression( Expression *& untyped, Type * type, const SymTab::Indexer & indexer );54 void resolveCtorInit( ConstructorInit * ctorInit, const SymTab::Indexer & indexer );55 void resolveStmtExpr( StmtExpr * stmtExpr, const SymTab::Indexer & indexer );56 /// Searches expr and returns the first DeletedExpr found, otherwise nullptr57 DeletedExpr * findDeletedExpr( Expression * expr );58 /// Resolves with-stmts and with-clauses on functions59 void resolveWithExprs( std::list< Declaration * > & translationUnit );60 35 61 36 /// Helper Type: Passes around information between various sub-calls. -
src/ResolvExpr/SpecCost.cc
r25f2798 r0bd3faf 76 76 77 77 public: 78 int get_count() const { return 0 <= count ? count : 0; }78 int result() const { return 0 <= count ? count : 0; } 79 79 80 80 // Mark specialization of base type. … … 125 125 return 0; 126 126 } 127 ast::Pass<SpecCounter> counter; 128 type->accept( counter ); 129 return counter.core.get_count(); 127 return ast::Pass<SpecCounter>::read( type ); 130 128 } 131 129 -
src/ResolvExpr/Unify.cc
r25f2798 r0bd3faf 105 105 /// If this isn't done when satifying ttype assertions, then argument lists can have 106 106 /// different size and structure when they should be compatible. 107 struct TtypeExpander _new: public ast::WithShortCircuiting, public ast::PureVisitor {107 struct TtypeExpander : public ast::WithShortCircuiting, public ast::PureVisitor { 108 108 ast::TypeEnvironment & tenv; 109 109 110 TtypeExpander _new( ast::TypeEnvironment & env ) : tenv( env ) {}110 TtypeExpander( ast::TypeEnvironment & env ) : tenv( env ) {} 111 111 112 112 const ast::Type * postvisit( const ast::TypeInstType * typeInst ) { … … 128 128 dst.reserve( src.size() ); 129 129 for ( const auto & d : src ) { 130 ast::Pass<TtypeExpander _new> expander{ env };130 ast::Pass<TtypeExpander> expander{ env }; 131 131 // TtypeExpander pass is impure (may mutate nodes in place) 132 132 // need to make nodes shared to prevent accidental mutation … … 268 268 } 269 269 270 class Unify _newfinal : public ast::WithShortCircuiting {270 class Unify final : public ast::WithShortCircuiting { 271 271 const ast::Type * type2; 272 272 ast::TypeEnvironment & tenv; … … 279 279 bool result; 280 280 281 Unify _new(281 Unify( 282 282 const ast::Type * type2, ast::TypeEnvironment & env, ast::AssertionSet & need, 283 283 ast::AssertionSet & have, const ast::OpenVarSet & open, WidenMode widen ) … … 606 606 if ( ! tuple2 ) return; 607 607 608 ast::Pass<TtypeExpander _new> expander{ tenv };608 ast::Pass<TtypeExpander> expander{ tenv }; 609 609 610 610 const ast::Type * flat = tuple->accept( expander ); … … 634 634 }; 635 635 636 // size_t Unify_new::traceId = Stats::Heap::new_stacktrace_id("Unify_new"); 636 // size_t Unify::traceId = Stats::Heap::new_stacktrace_id("Unify"); 637 637 638 bool unify( 638 639 const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2, … … 678 679 return env.bindVar( var2, type1, ast::TypeData{var2->base}, need, have, open, widen ); 679 680 } else { 680 return ast::Pass<Unify _new>::read(681 return ast::Pass<Unify>::read( 681 682 type1, type2, env, need, have, open, widen ); 682 683 } -
src/ResolvExpr/typeops.h
r25f2798 r0bd3faf 19 19 20 20 #include "AST/Type.hpp" 21 22 namespace SymTab {23 class Indexer;24 }25 21 26 22 namespace ResolvExpr {
Note:
See TracChangeset
for help on using the changeset viewer.