Changes in / [f6bceeb:641be0a]
- Location:
- src
- Files:
-
- 2 added
- 6 edited
-
Common/CompilerError.h (added)
-
Common/UnimplementedError.h (added)
-
Common/module.mk (modified) (2 diffs)
-
GenPoly/FindFunction.cc (modified) (3 diffs)
-
GenPoly/FindFunction.h (modified) (2 diffs)
-
GenPoly/GenPoly.cc (modified) (4 diffs)
-
GenPoly/GenPoly.h (modified) (1 diff)
-
main.cc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Common/module.mk
rf6bceeb r641be0a 20 20 Common/CodeLocationTools.hpp \ 21 21 Common/CodeLocationTools.cpp \ 22 Common/CompilerError.h \ 22 23 Common/Debug.h \ 23 24 Common/DeclStats.hpp \ … … 51 52 Common/Stats/Time.cc \ 52 53 Common/Stats/Time.h \ 54 Common/UnimplementedError.h \ 53 55 Common/UniqueName.cc \ 54 56 Common/UniqueName.h \ -
src/GenPoly/FindFunction.cc
rf6bceeb r641be0a 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Oct 7 17:05:20 202213 // Update Count : 711 // Last Modified By : Rob Schluntz 12 // Last Modified On : Fri Feb 05 12:22:20 2016 13 // Update Count : 6 14 14 // 15 15 … … 18 18 #include <utility> // for pair 19 19 20 #include "AST/Pass.hpp" // for Pass21 #include "AST/Type.hpp"22 20 #include "Common/PassVisitor.h" // for PassVisitor 23 21 #include "GenPoly/ErasableScopedMap.h" // for ErasableScopedMap<>::iterator … … 91 89 handleForall( pointerType->get_forall() ); 92 90 } 93 94 namespace {95 96 struct FindFunctionCore :97 public ast::WithGuards,98 public ast::WithShortCircuiting,99 public ast::WithVisitorRef<FindFunctionCore> {100 FindFunctionCore(101 std::vector<ast::ptr<ast::FunctionType>> & functions,102 const TypeVarMap & typeVars, FindFunctionPred predicate,103 bool replaceMode );104 105 void previsit( ast::FunctionType const * type );106 ast::Type const * postvisit( ast::FunctionType const * type );107 void previsit( ast::PointerType const * type );108 private:109 void handleForall( const ast::FunctionType::ForallList & forall );110 111 std::vector<ast::ptr<ast::FunctionType>> &functions;112 TypeVarMap typeVars;113 FindFunctionPred predicate;114 bool replaceMode;115 };116 117 FindFunctionCore::FindFunctionCore(118 std::vector<ast::ptr<ast::FunctionType>> & functions,119 const TypeVarMap &typeVars, FindFunctionPred predicate,120 bool replaceMode ) :121 functions( functions ), typeVars( typeVars ),122 predicate( predicate ), replaceMode( replaceMode ) {}123 124 void FindFunctionCore::handleForall( const ast::FunctionType::ForallList & forall ) {125 for ( const ast::ptr<ast::TypeInstType> & td : forall ) {126 TypeVarMap::iterator var = typeVars.find( *td );127 if ( var != typeVars.end() ) {128 typeVars.erase( var->first );129 } // if130 } // for131 }132 133 void FindFunctionCore::previsit( ast::FunctionType const * type ) {134 visit_children = false;135 GuardScope( typeVars );136 handleForall( type->forall );137 //ast::accept_all( type->returns, *visitor );138 // This might have to become ast::mutate_each with return.139 ast::accept_each( type->returns, *visitor );140 }141 142 ast::Type const * FindFunctionCore::postvisit( ast::FunctionType const * type ) {143 ast::Type const * ret = type;144 if ( predicate( type, typeVars ) ) {145 functions.push_back( type );146 if ( replaceMode ) {147 // replace type parameters in function type with void*148 ret = scrubTypeVars( ast::deepCopy( type ), typeVars );149 } // if150 } // if151 return ret;152 }153 154 void FindFunctionCore::previsit( ast::PointerType const * /*type*/ ) {155 GuardScope( typeVars );156 //handleForall( type->forall );157 }158 159 } // namespace160 161 void findFunction( const ast::Type * type,162 std::vector<ast::ptr<ast::FunctionType>> & functions,163 const TypeVarMap & typeVars, FindFunctionPred predicate ) {164 ast::Pass<FindFunctionCore> pass( functions, typeVars, predicate, false );165 type->accept( pass );166 //(void)type;167 //(void)functions;168 //(void)typeVars;169 //(void)predicate;170 }171 172 const ast::Type * findAndReplaceFunction( const ast::Type * type,173 std::vector<ast::ptr<ast::FunctionType>> & functions,174 const TypeVarMap & typeVars, FindFunctionPred predicate ) {175 ast::Pass<FindFunctionCore> pass( functions, typeVars, predicate, true );176 return type->accept( pass );177 //(void)functions;178 //(void)typeVars;179 //(void)predicate;180 //return type;181 }182 183 91 } // namespace GenPoly 184 92 -
src/GenPoly/FindFunction.h
rf6bceeb r641be0a 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Oct 7 10:30:00 202213 // Update Count : 311 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:23:36 2017 13 // Update Count : 2 14 14 // 15 15 … … 30 30 /// like `findFunction`, but also replaces the function type with void ()(void) 31 31 void findAndReplaceFunction( Type *&type, std::list< FunctionType const * > &functions, const TyVarMap &tyVars, FindFunctionPredicate predicate ); 32 33 typedef bool (*FindFunctionPred)( const ast::FunctionType *, const TypeVarMap & );34 35 /// Recursively walks `type`, placing all functions that match `predicate`36 /// under `typeVars` into `functions`.37 void findFunction( const ast::Type * type,38 std::vector<ast::ptr<ast::FunctionType>> & functions,39 const TypeVarMap & typeVars, FindFunctionPred predicate );40 /// Like findFunction, but also replaces the function type with `void ()(void)`.41 const ast::Type * findAndReplaceFunction( const ast::Type * type,42 std::vector<ast::ptr<ast::FunctionType>> & functions,43 const TypeVarMap & typeVars, FindFunctionPred predicate );44 45 32 } // namespace GenPoly 46 33 -
src/GenPoly/GenPoly.cc
rf6bceeb r641be0a 275 275 } 276 276 277 const ast::BaseInstType *isDynRet( const ast::FunctionType * func ) {278 if ( func->returns.empty() ) return nullptr;279 280 TypeVarMap forallTypes = { ast::TypeData() };281 makeTypeVarMap( func, forallTypes );282 return isDynType( func->returns.front(), forallTypes );283 }284 285 277 bool needsAdapter( FunctionType *adaptee, const TyVarMap &tyVars ) { 286 278 // if ( ! adaptee->get_returnVals().empty() && isPolyType( adaptee->get_returnVals().front()->get_type(), tyVars ) ) { … … 327 319 return 0; 328 320 } 329 330 const ast::Type * isPolyPtr(331 const ast::Type * type, const TypeVarMap & typeVars,332 const ast::TypeSubstitution * typeSubs ) {333 type = replaceTypeInst( type, typeSubs );334 335 if ( auto * ptr = dynamic_cast<ast::PointerType const *>( type ) ) {336 return isPolyType( ptr->base, typeVars, typeSubs );337 }338 return nullptr;339 }340 321 341 322 Type * hasPolyBase( Type *type, int *levels, const TypeSubstitution *env ) { … … 815 796 } 816 797 817 void addToTypeVarMap( const ast::TypeDecl * decl, TypeVarMap & typeVars ) {818 typeVars.insert( ast::TypeEnvKey( decl, 0, 0 ), ast::TypeData( decl ) );819 }820 821 798 void addToTypeVarMap( const ast::TypeInstType * type, TypeVarMap & typeVars ) { 822 typeVars.insert( ast::TypeEnvKey( *type ), ast::TypeData( type->base ) );799 typeVars.insert( *type, ast::TypeData( type->base ) ); 823 800 } 824 801 … … 845 822 } 846 823 847 void makeTypeVarMap( const ast::FunctionDecl * decl, TypeVarMap & typeVars ) {848 for ( auto & typeDecl : decl->type_params ) {849 addToTypeVarMap( typeDecl, typeVars );850 }851 }852 853 824 void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap ) { 854 825 for ( TyVarMap::const_iterator i = tyVarMap.begin(); i != tyVarMap.end(); ++i ) { -
src/GenPoly/GenPoly.h
rf6bceeb r641be0a 111 111 void addToTyVarMap( TypeDecl * tyVar, TyVarMap &tyVarMap ); 112 112 void addToTypeVarMap( const ast::TypeDecl * type, TypeVarMap & typeVars ); 113 void addToTypeVarMap( const ast::TypeInstType * type, TypeVarMap & typeVars );114 113 115 114 /// Adds the declarations in the forall list of type (and its pointed-to type if it's a pointer type) to `tyVarMap` 116 115 void makeTyVarMap( Type *type, TyVarMap &tyVarMap ); 117 116 void makeTypeVarMap( const ast::Type * type, TypeVarMap & typeVars ); 118 void makeTypeVarMap( const ast::FunctionDecl * decl, TypeVarMap & typeVars );119 117 120 118 /// Prints type variable map -
src/main.cc
rf6bceeb r641be0a 40 40 #include "CodeTools/TrackLoc.h" // for fillLocations 41 41 #include "Common/CodeLocationTools.hpp" // for forceFillCodeLocations 42 #include "Common/CompilerError.h" // for CompilerError 42 43 #include "Common/DeclStats.hpp" // for printDeclStats 43 44 #include "Common/ResolvProtoDump.hpp" // for dumpAsResolverProto 44 45 #include "Common/Stats.h" // for Stats 46 #include "Common/UnimplementedError.h" // for UnimplementedError 45 47 #include "Common/utility.h" // for deleteAll, filter, printAll 46 48 #include "Concurrency/Actors.hpp" // for implementActors … … 478 480 } // if 479 481 return EXIT_FAILURE; 482 } catch ( UnimplementedError & e ) { 483 cout << "Sorry, " << e.get_what() << " is not currently implemented" << endl; 484 if ( output != &cout ) { 485 delete output; 486 } // if 487 return EXIT_FAILURE; 488 } catch ( CompilerError & e ) { 489 cerr << "Compiler Error: " << e.get_what() << endl; 490 cerr << "(please report bugs to [REDACTED])" << endl; 491 if ( output != &cout ) { 492 delete output; 493 } // if 494 return EXIT_FAILURE; 480 495 } catch ( std::bad_alloc & ) { 481 496 cerr << "*cfa-cpp compilation error* std::bad_alloc" << endl;
Note:
See TracChangeset
for help on using the changeset viewer.