- Timestamp:
- Jan 4, 2023, 1:44:19 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 339e30a, a14926b
- Parents:
- 0348fd8 (diff), 66a89e7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src
- Files:
-
- 10 edited
-
AST/Pass.hpp (modified) (2 diffs)
-
AST/Pass.proto.hpp (modified) (2 diffs)
-
CompilationState.cc (modified) (1 diff)
-
CompilationState.h (modified) (1 diff)
-
GenPoly/Box.cc (modified) (3 diffs)
-
GenPoly/ScrubTyVars.cc (modified) (4 diffs)
-
GenPoly/ScrubTyVars.h (modified) (5 diffs)
-
Parser/RunParser.cpp (modified) (3 diffs)
-
Parser/RunParser.hpp (modified) (3 diffs)
-
main.cc (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Pass.hpp
r0348fd8 rd99a716 86 86 { 87 87 // After the pass is constructed, check if it wants the have a pointer to the wrapping visitor 88 type * const * visitor = __pass::visitor( core, 0);89 if (visitor) {88 type * const * visitor = __pass::visitor( core, 0 ); 89 if ( visitor ) { 90 90 *const_cast<type **>( visitor ) = this; 91 91 } … … 98 98 99 99 /// If the core defines a result, call it if possible, otherwise return it. 100 inline auto get_result() -> decltype( __pass:: get_result( core, '0' ) ) {101 return __pass:: get_result( core, '0' );100 inline auto get_result() -> decltype( __pass::result::get( core, '0' ) ) { 101 return __pass::result::get( core, '0' ); 102 102 } 103 103 -
src/AST/Pass.proto.hpp
r0348fd8 rd99a716 489 489 template<typename core_t> 490 490 static inline auto replace( core_t &, long, const ast::TypeInstType *& ) {} 491 492 491 } // namespace forall 493 492 … … 506 505 } 507 506 508 template<typename core_t> 509 static inline auto get_result( core_t & core, char ) -> decltype( core.result() ) { 510 return core.result(); 511 } 512 513 template<typename core_t> 514 static inline auto get_result( core_t & core, int ) -> decltype( core.result ) { 515 return core.result; 516 } 517 518 template<typename core_t> 519 static inline void get_result( core_t &, long ) {} 507 // For passes, usually utility passes, that have a result. 508 namespace result { 509 template<typename core_t> 510 static inline auto get( core_t & core, char ) -> decltype( core.result() ) { 511 return core.result(); 512 } 513 514 template<typename core_t> 515 static inline auto get( core_t & core, int ) -> decltype( core.result ) { 516 return core.result; 517 } 518 519 template<typename core_t> 520 static inline void get( core_t &, long ) {} 521 } 520 522 } // namespace __pass 521 523 } // namespace ast -
src/CompilationState.cc
r0348fd8 rd99a716 33 33 useNewAST = true, 34 34 nomainp = false, 35 parsep = false,36 35 resolvep = false, 37 36 resolvprotop = false, -
src/CompilationState.h
r0348fd8 rd99a716 32 32 useNewAST, 33 33 nomainp, 34 parsep,35 34 resolvep, 36 35 resolvprotop, -
src/GenPoly/Box.cc
r0348fd8 rd99a716 424 424 namespace { 425 425 std::string makePolyMonoSuffix( FunctionType const * function, const TyVarMap &tyVars ) { 426 std::stringstream name;427 428 426 // NOTE: this function previously used isPolyObj, which failed to produce 429 427 // the correct thing in some situations. It's not clear to me why this wasn't working. … … 432 430 // to take those polymorphic types as pointers. Therefore, there can be two different functions 433 431 // with the same mangled name, so we need to further mangle the names. 432 std::stringstream name; 434 433 for ( DeclarationWithType const * const ret : function->returnVals ) { 435 if ( isPolyType( ret->get_type(), tyVars ) ) { 436 name << "P"; 437 } else { 438 name << "M"; 439 } 440 } 441 name << "_"; 434 name << ( isPolyType( ret->get_type(), tyVars ) ? 'P' : 'M' ); 435 } 436 name << '_'; 442 437 for ( DeclarationWithType const * const arg : function->parameters ) { 443 if ( isPolyType( arg->get_type(), tyVars ) ) { 444 name << "P"; 445 } else { 446 name << "M"; 447 } 448 } // for 438 name << ( isPolyType( arg->get_type(), tyVars ) ? 'P' : 'M' ); 439 } 449 440 return name.str(); 450 441 } … … 565 556 // even when converted to strings, sort in the original order. 566 557 // (At least, that is the best explination I have.) 567 for ( std::pair< std::string, TypeDecl::Data> const & tyParam : exprTyVars ) {558 for ( std::pair<const std::string, TypeDecl::Data> const & tyParam : exprTyVars ) { 568 559 if ( !tyParam.second.isComplete ) continue; 569 560 Type *concrete = env->lookup( tyParam.first ); -
src/GenPoly/ScrubTyVars.cc
r0348fd8 rd99a716 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Oct 7 15:42:00 202213 // Update Count : 512 // Last Modified On : Wed Dec 7 17:01:00 2022 13 // Update Count : 6 14 14 // 15 15 … … 117 117 namespace { 118 118 119 enum class ScrubMode {120 FromMap,121 DynamicFromMap,122 All,123 };124 125 119 struct ScrubTypeVars : 126 120 public ast::WithGuards, … … 253 247 } 254 248 249 } // namespace 250 255 251 const ast::Node * scrubTypeVarsBase( 256 const ast::Node * target, 257 ScrubMode mode, const TypeVarMap * typeVars ) { 252 const ast::Node * node, const TypeVarMap * typeVars, ScrubMode mode ) { 258 253 if ( ScrubMode::All == mode ) { 259 254 assert( nullptr == typeVars ); … … 262 257 } 263 258 ast::Pass<ScrubTypeVars> visitor( mode, typeVars ); 264 return target->accept( visitor ); 265 } 266 267 } // namespace 268 269 template<> 270 ast::Node const * scrubTypeVars<ast::Node>( 271 const ast::Node * target, const TypeVarMap & typeVars ) { 272 return scrubTypeVarsBase( target, ScrubMode::FromMap, &typeVars ); 273 } 274 275 template<> 276 ast::Node const * scrubTypeVarsDynamic<ast::Node>( 277 ast::Node const * target, const TypeVarMap & typeVars ) { 278 return scrubTypeVarsBase( target, ScrubMode::DynamicFromMap, &typeVars ); 279 } 280 281 template<> 282 ast::Node const * scrubAllTypeVars<ast::Node>( const ast::Node * target ) { 283 return scrubTypeVarsBase( target, ScrubMode::All, nullptr ); 259 return node->accept( visitor ); 284 260 } 285 261 -
src/GenPoly/ScrubTyVars.h
r0348fd8 rd99a716 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Oct 7 15:51:00 202213 // Update Count : 412 // Last Modified On : Wed Dec 7 16:57:00 2022 13 // Update Count : 5 14 14 // 15 15 … … 109 109 } 110 110 111 // ScrubMode and scrubTypeVarsBase are internal. 112 enum class ScrubMode { FromMap, DynamicFromMap, All }; 113 114 const ast::Node * scrubTypeVarsBase( 115 const ast::Node * target, const TypeVarMap * typeVars, ScrubMode mode ); 116 117 111 118 /// For all polymorphic types with type variables in `typeVars`, 112 119 /// replaces generic types, dtypes, and ftypes with the appropriate void type, … … 116 123 node_t const * target, const TypeVarMap & typeVars ) { 117 124 return strict_dynamic_cast<node_t const *>( 118 scrubTypeVars <ast::Node>( target, typeVars) );125 scrubTypeVarsBase( target, &typeVars, ScrubMode::FromMap ) ); 119 126 } 120 127 … … 123 130 /// and sizeof/alignof expressions with the proper variable. 124 131 template<typename node_t> 125 ast::Nodeconst * scrubTypeVarsDynamic(132 node_t const * scrubTypeVarsDynamic( 126 133 node_t const * target, const TypeVarMap & typeVars ) { 127 134 return strict_dynamic_cast<node_t const *>( 128 scrubTypeVars Dynamic<ast::Node>( target, typeVars) );135 scrubTypeVarsBase( target, &typeVars, ScrubMode::DynamicFromMap ) ); 129 136 } 130 137 … … 134 141 node_t const * scrubAllTypeVars( node_t const * target ) { 135 142 return strict_dynamic_cast<node_t const *>( 136 scrub AllTypeVars<ast::Node>( target) );143 scrubTypeVarsBase( target, nullptr, ScrubMode::All ) ); 137 144 } 138 139 // We specialize for Node as a base case.140 template<>141 ast::Node const * scrubTypeVars<ast::Node>(142 const ast::Node * target, const TypeVarMap & typeVars );143 144 template<>145 ast::Node const * scrubTypeVarsDynamic<ast::Node>(146 ast::Node const * target, const TypeVarMap & typeVars );147 148 template<>149 ast::Node const * scrubAllTypeVars<ast::Node>( const ast::Node * target );150 145 151 146 } // namespace GenPoly -
src/Parser/RunParser.cpp
r0348fd8 rd99a716 10 10 // Created On : Mon Dec 19 11:00:00 2022 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Dec 19 11:15:00 202213 // Update Count : 012 // Last Modified On : Thr Dec 22 10:18:00 2022 13 // Update Count : 1 14 14 // 15 15 16 16 #include "RunParser.hpp" 17 17 18 #include "AST/Convert.hpp" // for convert 19 #include "AST/TranslationUnit.hpp" // for TranslationUnit 20 #include "CodeTools/TrackLoc.h" // for fillLocations 21 #include "Common/CodeLocationTools.hpp" // for forceFillCodeLocations 18 22 #include "Parser/ParseNode.h" // for DeclarationNode, buildList 19 23 #include "Parser/TypedefTable.h" // for TypedefTable … … 41 45 } // parse 42 46 43 void dumpParseTree( std::ostream & out ) { 44 parseTree->printList( out ); 45 delete parseTree; 46 parseTree = nullptr; 47 } 48 49 std::list<Declaration *> buildUnit(void) { 47 ast::TranslationUnit buildUnit(void) { 50 48 std::list<Declaration *> translationUnit; 51 49 buildList( parseTree, translationUnit ); … … 54 52 parseTree = nullptr; 55 53 56 return translationUnit; 54 // When the parse/buildList code is translated to the new ast, these 55 // fill passes (and the one after 'Hoist Type Decls') should be redundent 56 // because the code locations should already be filled. 57 CodeTools::fillLocations( translationUnit ); 58 ast::TranslationUnit transUnit = convert( std::move( translationUnit ) ); 59 forceFillCodeLocations( transUnit ); 60 return transUnit; 57 61 } 58 62 -
src/Parser/RunParser.hpp
r0348fd8 rd99a716 10 10 // Created On : Mon Dec 19 10:42:00 2022 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Dec 19 11:15:00 202213 // Update Count : 012 // Last Modified On : Thr Dec 22 10:23:00 2022 13 // Update Count : 1 14 14 // 15 15 … … 17 17 18 18 #include <iosfwd> // for ostream 19 #include <list> // for list20 19 21 20 #include "SynTree/LinkageSpec.h" // for Spec 22 class Declaration; 21 namespace ast { 22 class TranslationUnit; 23 } 23 24 24 25 // The Parser does not have an enclosing namespace. … … 30 31 void parse( FILE * input, LinkageSpec::Spec linkage, bool alwaysExit = false ); 31 32 32 /// Drain the internal accumulator of parsed code and print it to the stream.33 void dumpParseTree( std::ostream & );34 35 33 /// Drain the internal accumulator of parsed code and build a translation 36 34 /// unit from it. 37 std::list<Declaration *>buildUnit(void);35 ast::TranslationUnit buildUnit(void); 38 36 39 37 // Local Variables: // -
src/main.cc
r0348fd8 rd99a716 228 228 ostream * output = & cout; 229 229 list< Declaration * > translationUnit; 230 ast::TranslationUnit transUnit; 230 231 231 232 Signal( SIGSEGV, sigSegvBusHandler, SA_SIGINFO ); … … 294 295 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, yydebug ); 295 296 296 if ( parsep ) { 297 dumpParseTree( cout ); 298 return EXIT_SUCCESS; 299 } // if 300 301 translationUnit = buildUnit(); 297 transUnit = buildUnit(); 302 298 303 299 if ( astp ) { 304 dump( translationUnit ); 305 return EXIT_SUCCESS; 306 } // if 307 308 // Temporary: fill locations after parsing so that every node has a location, for early error messages. 309 // Eventually we should pass the locations from the parser to every node, but this quick and dirty solution 310 // works okay for now. 311 CodeTools::fillLocations( translationUnit ); 300 dump( std::move( transUnit ) ); 301 return EXIT_SUCCESS; 302 } // if 303 312 304 Stats::Time::StopBlock(); 313 305 … … 316 308 ast::pass_visitor_stats.max = Stats::Counters::build<Stats::Counters::MaxCounter<double>>("Max depth - New"); 317 309 } 318 auto transUnit = convert( std::move( translationUnit ) ); 319 320 forceFillCodeLocations( transUnit ); 321 322 PASS( "Translate Exception Declarations", ControlStruct::translateExcept( transUnit ) ); 323 if ( exdeclp ) { 324 dump( std::move( transUnit ) ); 325 return EXIT_SUCCESS; 326 } 327 328 PASS( "Verify Ctor, Dtor & Assign", Validate::verifyCtorDtorAssign( transUnit ) ); 310 329 311 PASS( "Hoist Type Decls", Validate::hoistTypeDecls( transUnit ) ); 330 312 // Hoist Type Decls pulls some declarations out of contexts where … … 333 315 forceFillCodeLocations( transUnit ); 334 316 317 PASS( "Translate Exception Declarations", ControlStruct::translateExcept( transUnit ) ); 318 if ( exdeclp ) { 319 dump( std::move( transUnit ) ); 320 return EXIT_SUCCESS; 321 } 322 323 PASS( "Verify Ctor, Dtor & Assign", Validate::verifyCtorDtorAssign( transUnit ) ); 335 324 PASS( "Replace Typedefs", Validate::replaceTypedef( transUnit ) ); 336 325 PASS( "Fix Return Types", Validate::fixReturnTypes( transUnit ) ); … … 474 463 if ( errorp ) { 475 464 cerr << "---AST at error:---" << endl; 476 dump( translationUnit, cerr ); 465 // We check which section the errors came from without looking at 466 // transUnit because std::move means it could look like anything. 467 if ( !translationUnit.empty() ) { 468 dump( translationUnit, cerr ); 469 } else { 470 dump( std::move( transUnit ), cerr ); 471 } 477 472 cerr << endl << "---End of AST, begin error message:---\n" << endl; 478 473 } // if … … 578 573 { "rproto", resolvprotop, true, "resolver-proto instance" }, 579 574 { "rsteps", resolvep, true, "print resolver steps" }, 580 { "tree", parsep, true, "print parse tree" },581 575 // code dumps 582 576 { "ast", astp, true, "print AST after parsing" },
Note:
See TracChangeset
for help on using the changeset viewer.