- Timestamp:
- Sep 19, 2022, 8:11:02 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation
- Children:
- aa9f215
- Parents:
- ebf8ca5 (diff), ae1d151 (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:
-
- 1 added
- 42 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Decl.hpp
rebf8ca5 r23a08aa0 217 217 218 218 /// convenience accessor to match Type::isComplete() 219 bool isComplete() { return sized; }219 bool isComplete() const { return sized; } 220 220 221 221 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } -
src/AST/DeclReplacer.cpp
rebf8ca5 r23a08aa0 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed May 8 13:00:00 2019 11 // Last Modified By : A aron B. Moss12 // Last Modified On : Wed May 8 13:00:00 201913 // Update Count : 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Sep 15 11:55:00 2022 13 // Update Count : 2 14 14 // 15 15 16 16 #include "DeclReplacer.hpp" 17 17 18 #include "Expr.hpp" 19 #include "Pass.hpp" 18 20 #include "Type.hpp" 19 20 #include "Pass.hpp"21 21 22 22 namespace ast { 23 23 24 24 namespace DeclReplacer { 25 namespace {26 struct DeclReplacer {27 private:28 const DeclMap & declMap;29 const TypeMap & typeMap;30 bool debug;31 25 32 public: 33 DeclReplacer(const DeclMap & declMap, const TypeMap & typeMap, bool debug) 34 : declMap( declMap ), typeMap( typeMap ), debug( debug ) 35 {} 26 namespace { 27 struct DeclReplacer { 28 private: 29 const DeclMap & declMap; 30 const TypeMap & typeMap; 31 bool debug; 36 32 37 const ast::VariableExpr * previsit( const ast::VariableExpr * ); 38 const ast::TypeInstType * previsit( const ast::TypeInstType * ); 39 }; 33 public: 34 DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug ) 35 : declMap( declMap ), typeMap( typeMap ), debug( debug ) 36 {} 40 37 41 struct VarExprReplacer { 42 private: 43 const ExprMap & exprMap; 44 45 public: 46 VarExprReplacer(const ExprMap & exprMap): exprMap (exprMap) {} 38 const ast::VariableExpr * previsit( const ast::VariableExpr * ); 39 const ast::TypeInstType * previsit( const ast::TypeInstType * ); 40 }; 47 41 48 const Expr * postvisit (const VariableExpr *); 49 }; 42 struct VarExprReplacer { 43 private: 44 const ExprMap & exprMap; 45 46 public: 47 VarExprReplacer( const ExprMap & exprMap ) : exprMap( exprMap ) {} 48 49 const Expr * postvisit( const VariableExpr * ); 50 }; 51 } // namespace 52 53 const ast::Node * replace( const ast::Node * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) { 54 if(!node) return nullptr; 55 Pass<DeclReplacer> replacer = { declMap, typeMap, debug }; 56 return node->accept( replacer ); 57 } 58 59 const ast::Node * replace( const ast::Node * node, const DeclMap & declMap, bool debug ) { 60 TypeMap typeMap; 61 return replace( node, declMap, typeMap, debug ); 62 } 63 64 const ast::Node * replace( const ast::Node * node, const TypeMap & typeMap, bool debug ) { 65 DeclMap declMap; 66 return replace( node, declMap, typeMap, debug ); 67 } 68 69 const ast::Node * replace( const ast::Node * node, const ExprMap & exprMap ) { 70 Pass<VarExprReplacer> replacer = {exprMap}; 71 return node->accept( replacer ); 72 } 73 74 namespace { 75 // replace variable with new node from decl map 76 const ast::VariableExpr * DeclReplacer::previsit( const VariableExpr * varExpr ) { 77 // xxx - assertions and parameters aren't accounted for in this... (i.e. they aren't inserted into the map when it's made, only DeclStmts are) 78 if ( !declMap.count( varExpr->var ) ) return varExpr; 79 80 auto replacement = declMap.at( varExpr->var ); 81 if ( debug ) { 82 std::cerr << "replacing variable reference: " 83 << (void*)varExpr->var.get() << " " << varExpr->var 84 << " with " << (void*)replacement << " " << replacement 85 << std::endl; 86 } 87 auto nexpr = mutate(varExpr); 88 nexpr->var = replacement; 89 return nexpr; 50 90 } 51 91 52 const ast::Node * replace( const ast::Node * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) { 53 if(!node) return nullptr; 54 Pass<DeclReplacer> replacer = { declMap, typeMap, debug }; 55 return node->accept( replacer ); 92 const TypeInstType * DeclReplacer::previsit( const TypeInstType * inst ) { 93 if ( !typeMap.count( inst->base ) ) return inst; 94 95 auto replacement = typeMap.at( inst->base ); 96 if ( debug ) { 97 std::cerr << "replacing type reference: " 98 << (void*)inst->base.get() << " " << inst->base 99 << " with " << (void*)replacement << " " << replacement 100 << std::endl; 101 } 102 auto ninst = mutate(inst); 103 ninst->base = replacement; 104 return ninst; 56 105 } 57 106 58 const ast::Node * replace( const ast::Node * node, const DeclMap & declMap, bool debug) {59 TypeMap typeMap;60 return replace( node, declMap, typeMap, debug);107 const Expr * VarExprReplacer::postvisit( const VariableExpr * expr ) { 108 if ( !exprMap.count( expr->var ) ) return expr; 109 return exprMap.at( expr->var ); 61 110 } 111 } // namespace 62 112 63 const ast::Node * replace( const ast::Node * node, const TypeMap & typeMap, bool debug ) { 64 DeclMap declMap; 65 return replace( node, declMap, typeMap, debug ); 66 } 113 } // namespace DeclReplacer 67 114 68 const ast::Node * replace( const ast::Node * node, const ExprMap & exprMap) { 69 Pass<VarExprReplacer> replacer = {exprMap}; 70 return node->accept( replacer ); 71 } 72 73 namespace { 74 // replace variable with new node from decl map 75 const ast::VariableExpr * DeclReplacer::previsit( const VariableExpr * varExpr ) { 76 // xxx - assertions and parameters aren't accounted for in this... (i.e. they aren't inserted into the map when it's made, only DeclStmts are) 77 if ( !declMap.count( varExpr->var ) ) return varExpr; 78 79 auto replacement = declMap.at( varExpr->var ); 80 if ( debug ) { 81 std::cerr << "replacing variable reference: " 82 << (void*)varExpr->var.get() << " " << varExpr->var 83 << " with " << (void*)replacement << " " << replacement 84 << std::endl; 85 } 86 auto nexpr = mutate(varExpr); 87 nexpr->var = replacement; 88 return nexpr; 89 } 90 91 const TypeInstType * DeclReplacer::previsit( const TypeInstType * inst ) { 92 if ( !typeMap.count( inst->base ) ) return inst; 93 94 auto replacement = typeMap.at( inst->base ); 95 if ( debug ) { 96 std::cerr << "replacing type reference: " 97 << (void*)inst->base.get() << " " << inst->base 98 << " with " << (void*)replacement << " " << replacement 99 << std::endl; 100 } 101 auto ninst = mutate(inst); 102 ninst->base = replacement; 103 return ninst; 104 } 105 106 const Expr * VarExprReplacer::postvisit( const VariableExpr * expr ) { 107 if (!exprMap.count(expr->var)) return expr; 108 109 return exprMap.at(expr->var); 110 } 111 112 } 113 } 114 115 } 115 } // namespace ast 116 116 117 117 // Local Variables: // -
src/AST/Pass.hpp
rebf8ca5 r23a08aa0 327 327 struct PureVisitor {}; 328 328 329 struct WithCodeLocation { 330 const CodeLocation * location = nullptr; 331 }; 332 329 333 /// Keep track of the polymorphic const TypeSubstitution * typeSubs for the current expression. 330 334 struct WithConstTypeSubstitution { -
src/AST/Pass.impl.hpp
rebf8ca5 r23a08aa0 25 25 #define VISIT_START( node ) \ 26 26 using namespace ast; \ 27 /* back-up the last known code location */ \ 28 __attribute__((unused)) auto loc_guard = ast::__pass::make_location_guard( core, node, 0 ); \ 27 29 /* back-up the visit children */ \ 28 30 __attribute__((unused)) ast::__pass::visit_children_guard guard1( ast::__pass::visit_children(core, 0) ); \ -
src/AST/Pass.proto.hpp
rebf8ca5 r23a08aa0 326 326 } 327 327 328 template< typename core_t, typename node_t > 329 static auto make_location_guard( core_t & core, node_t * node, int ) 330 -> decltype( node->location, ValueGuardPtr<const CodeLocation *>( &core.location ) ) { 331 ValueGuardPtr<const CodeLocation *> guard( &core.location ); 332 core.location = &node->location; 333 return guard; 334 } 335 336 template< typename core_t, typename node_t > 337 static auto make_location_guard( core_t &, node_t *, long ) -> int { 338 return 0; 339 } 340 328 341 // Another feature of the templated visitor is that it calls beginScope()/endScope() for compound statement. 329 342 // All passes which have such functions are assumed desire this behaviour -
src/AST/Print.cpp
rebf8ca5 r23a08aa0 33 33 { 34 34 return array<C,sizeof...(T)>{ 35 forward<T>(values)...35 std::forward<T>(values)... 36 36 }; 37 37 } … … 86 86 87 87 static constexpr auto StorageClasses = make_array<const char*>( 88 "extern", "static", "auto", "register", "_ Thread_local"88 "extern", "static", "auto", "register", "__thread", "_Thread_local" 89 89 ); 90 90 … … 215 215 ++indent; 216 216 ptrToEnum->base->accept( *this ); 217 --indent; 217 --indent; 218 218 } 219 219 … … 1623 1623 // if the wrong size is specified 1624 1624 constexpr array<const char*, 3> Printer::Names::FuncSpecifiers; 1625 constexpr array<const char*, 5> Printer::Names::StorageClasses;1625 constexpr array<const char*, 6> Printer::Names::StorageClasses; 1626 1626 constexpr array<const char*, 6> Printer::Names::Qualifiers; 1627 1627 } -
src/AST/StorageClasses.hpp
rebf8ca5 r23a08aa0 24 24 /// Bitflags for storage classes 25 25 enum { 26 Extern = 1 << 0, 27 Static = 1 << 1, 28 Auto = 1 << 2, 29 Register = 1 << 3, 30 ThreadLocal = 1 << 4, 31 NumClasses = 5 26 Extern = 1 << 0, 27 Static = 1 << 1, 28 Auto = 1 << 2, 29 Register = 1 << 3, 30 ThreadLocalGcc = 1 << 4, 31 ThreadLocalC11 = 1 << 5, 32 NumClasses = 6 32 33 }; 33 34 … … 37 38 unsigned int val; 38 39 struct { 39 bool is_extern : 1; 40 bool is_static : 1; 41 bool is_auto : 1; 42 bool is_register : 1; 43 bool is_threadlocal : 1; 40 bool is_extern : 1; 41 bool is_static : 1; 42 bool is_auto : 1; 43 bool is_register : 1; 44 bool is_threadlocalGcc : 1; 45 bool is_threadlocalC11 : 1; 44 46 }; 45 47 … … 48 50 49 51 constexpr class_flags( unsigned int val = 0 ) : val(val) {} 52 53 bool is_threadlocal_any() { return this->is_threadlocalC11 || this->is_threadlocalGcc; } 50 54 }; 51 55 -
src/AST/Type.cpp
rebf8ca5 r23a08aa0 143 143 TraitInstType::TraitInstType( 144 144 const TraitDecl * b, CV::Qualifiers q, std::vector<ptr<Attribute>>&& as ) 145 : BaseInstType( b->name, q, move(as) ), base( b ) {}145 : BaseInstType( b->name, q, std::move(as) ), base( b ) {} 146 146 147 147 // --- TypeInstType … … 149 149 TypeInstType::TypeInstType( const TypeDecl * b, 150 150 CV::Qualifiers q, std::vector<ptr<Attribute>> && as ) 151 : BaseInstType( b->name, q, move(as) ), base( b ), kind( b->kind ) {}151 : BaseInstType( b->name, q, std::move(as) ), base( b ), kind( b->kind ) {} 152 152 153 153 void TypeInstType::set_base( const TypeDecl * b ) { … … 161 161 162 162 TupleType::TupleType( std::vector<ptr<Type>> && ts, CV::Qualifiers q ) 163 : Type( q ), types( move(ts) ), members() {163 : Type( q ), types( std::move(ts) ), members() { 164 164 // This constructor is awkward. `TupleType` needs to contain objects so that members can be 165 165 // named, but members without initializer nodes end up getting constructors, which breaks -
src/AST/Type.hpp
rebf8ca5 r23a08aa0 83 83 template< enum Node::ref_type ref_t > 84 84 void reset_qualifiers( ptr_base< Type, ref_t > & p, CV::Qualifiers q = {} ) { 85 if ( p->qualifiers .val != q.val) p.get_and_mutate()->qualifiers = q;85 if ( p->qualifiers != q ) p.get_and_mutate()->qualifiers = q; 86 86 } 87 87 … … 89 89 template< enum Node::ref_type ref_t > 90 90 void add_qualifiers( ptr_base< Type, ref_t > & p, CV::Qualifiers q ) { 91 if ( ( p->qualifiers .val & q.val ) != q.val) p.get_and_mutate()->qualifiers |= q;91 if ( ( p->qualifiers & q ) != q ) p.get_and_mutate()->qualifiers |= q; 92 92 } 93 93 … … 95 95 template< enum Node::ref_type ref_t > 96 96 void remove_qualifiers( ptr_base< Type, ref_t > & p, CV::Qualifiers q ) { 97 if ( ( p->qualifiers .val & q.val) != 0 ) p.get_and_mutate()->qualifiers -= q;97 if ( ( p->qualifiers & q ) != 0 ) p.get_and_mutate()->qualifiers -= q; 98 98 } 99 99 … … 412 412 std::string typeString() const { return std::string("_") + std::to_string(formal_usage) + "_" + std::to_string(expr_id) + "_" + base->name; } 413 413 bool operator==(const TypeEnvKey & other) const { return base == other.base && formal_usage == other.formal_usage && expr_id == other.expr_id; } 414 415 414 }; 416 415 -
src/CodeGen/CodeGenerator.cc
rebf8ca5 r23a08aa0 493 493 assert( false ); 494 494 } // switch 495 } else if( varExpr->get_var()->get_linkage() == LinkageSpec::BuiltinCFA && varExpr->get_var()->get_name() == "intptr" ) { 496 // THIS is a hack to make it a constant until a proper constexpr solution is created 497 output << "((void*)"; 498 std::list< Expression* >::iterator arg = applicationExpr->get_args().begin(); 499 (*arg++)->accept( *visitor ); 500 output << ")"; 495 501 } else { 496 502 varExpr->accept( *visitor ); -
src/Common/utility.h
rebf8ca5 r23a08aa0 322 322 323 323 ValueGuardPtr(T * inRef) : old( inRef ? *inRef : T() ), ref(inRef) {} 324 ValueGuardPtr(const ValueGuardPtr& other) = delete; 325 ValueGuardPtr(ValueGuardPtr&& other) : old(other.old), ref(other.ref) { other.ref = nullptr; } 324 326 ~ValueGuardPtr() { if( ref ) *ref = old; } 325 327 }; -
src/CompilationState.cc
rebf8ca5 r23a08aa0 31 31 genproto = false, 32 32 deterministic_output = false, 33 useNewAST = CFA_USE_NEW_AST,33 useNewAST = true, 34 34 nomainp = false, 35 35 parsep = false, -
src/Concurrency/Keywords.cc
rebf8ca5 r23a08aa0 508 508 ObjectDecl * vtable_object = Virtual::makeVtableForward( 509 509 "_default_vtable_object_declaration", 510 vtable_decl->makeInst( move( poly_args ) ) );510 vtable_decl->makeInst( std::move( poly_args ) ) ); 511 511 declsToAddBefore.push_back( vtable_object ); 512 512 declsToAddBefore.push_back( … … 681 681 void lock (monitor_t & this) { 682 682 lock(get_monitor(this)); 683 } 683 } 684 684 */ 685 685 FunctionDecl * lock_decl = new FunctionDecl( … … 700 700 CompoundStmt * lock_statement = new CompoundStmt(); 701 701 lock_statement->push_back( 702 new ExprStmt( 702 new ExprStmt( 703 703 new UntypedExpr ( 704 704 new NameExpr( "lock" ), … … 716 716 void unlock (monitor_t & this) { 717 717 unlock(get_monitor(this)); 718 } 718 } 719 719 */ 720 720 FunctionDecl * unlock_decl = new FunctionDecl( … … 736 736 737 737 unlock_statement->push_back( 738 new ExprStmt( 738 new ExprStmt( 739 739 new UntypedExpr( 740 740 new NameExpr( "unlock" ), … … 746 746 ); 747 747 unlock_decl->set_statements( unlock_statement ); 748 748 749 749 // pushes routines to declsToAddAfter to add at a later time 750 750 declsToAddAfter.push_back( lock_decl ); … … 1054 1054 assert( !thread_guard_decl ); 1055 1055 thread_guard_decl = decl; 1056 } 1056 } 1057 1057 else if ( decl->name == "__mutex_stmt_lock_guard" && decl->body ) { 1058 1058 assert( !lock_guard_decl ); … … 1206 1206 new NameExpr( "__get_mutexstmt_lock_type" ), 1207 1207 { args.front()->clone() } 1208 ) 1208 ) 1209 1209 ) 1210 1210 ), … … 1225 1225 1226 1226 StructInstType * lock_guard_struct = new StructInstType( noQualifiers, lock_guard_decl ); 1227 TypeExpr * lock_type_expr = new TypeExpr( 1227 TypeExpr * lock_type_expr = new TypeExpr( 1228 1228 new TypeofType( noQualifiers, new UntypedExpr( 1229 1229 new NameExpr( "__get_mutexstmt_lock_type" ), 1230 1230 { args.front()->clone() } 1231 ) 1232 ) 1231 ) 1232 ) 1233 1233 ); 1234 1234 -
src/Concurrency/Waitfor.cc
rebf8ca5 r23a08aa0 402 402 403 403 clause.target.function = nullptr; 404 clause.target.arguments. empty();404 clause.target.arguments.clear(); 405 405 clause.condition = nullptr; 406 406 } -
src/Concurrency/WaitforNew.cpp
rebf8ca5 r23a08aa0 101 101 namespace { 102 102 103 class GenerateWaitForCore :103 class GenerateWaitForCore final : 104 104 public ast::WithSymbolTable, public ast::WithConstTranslationUnit { 105 105 const ast::FunctionDecl * decl_waitfor = nullptr; -
src/ControlStruct/ExceptTranslateNew.cpp
rebf8ca5 r23a08aa0 32 32 } 33 33 34 class TranslateThrowsCore : public ast::WithGuards {34 class TranslateThrowsCore final : public ast::WithGuards { 35 35 const ast::ObjectDecl * terminateHandlerExcept; 36 36 enum Context { NoHandler, TerHandler, ResHandler } currentContext; … … 136 136 137 137 138 class TryMutatorCore {138 class TryMutatorCore final { 139 139 // The built in types used in translation. 140 140 const ast::StructDecl * except_decl; -
src/ControlStruct/LabelFixer.cc
rebf8ca5 r23a08aa0 119 119 120 120 // Builds a table that maps a label to its defining statement. 121 std::map<Label, Statement * > * LabelFixer::resolveJumps() throw ( SemanticErrorException ){121 std::map<Label, Statement * > * LabelFixer::resolveJumps() { 122 122 std::map< Label, Statement * > *ret = new std::map< Label, Statement * >(); 123 123 for ( std::map< Label, Entry * >::iterator i = labelTable.begin(); i != labelTable.end(); ++i ) { -
src/ControlStruct/LabelFixer.h
rebf8ca5 r23a08aa0 33 33 LabelFixer( LabelGenerator *gen = 0 ); 34 34 35 std::map < Label, Statement * > *resolveJumps() throw ( SemanticErrorException );35 std::map < Label, Statement * > *resolveJumps(); 36 36 37 37 // Declarations -
src/ControlStruct/MLEMutator.cc
rebf8ca5 r23a08aa0 141 141 142 142 143 Statement *MultiLevelExitMutator::postmutate( BranchStmt *branchStmt ) 144 throw ( SemanticErrorException ) { 143 Statement *MultiLevelExitMutator::postmutate( BranchStmt *branchStmt ) { 145 144 std::string originalTarget = branchStmt->originalTarget; 146 145 -
src/ControlStruct/MLEMutator.h
rebf8ca5 r23a08aa0 41 41 42 42 void premutate( CompoundStmt *cmpndStmt ); 43 Statement * postmutate( BranchStmt *branchStmt ) throw ( SemanticErrorException );43 Statement * postmutate( BranchStmt *branchStmt ); 44 44 void premutate( WhileDoStmt *whileDoStmt ); 45 45 Statement * postmutate( WhileDoStmt *whileDoStmt ); -
src/GenPoly/GenPoly.cc
rebf8ca5 r23a08aa0 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Jun 29 21:45:53 201613 // Update Count : 1 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Sep 14 9:24:00 2022 13 // Update Count : 15 14 14 // 15 15 … … 83 83 } 84 84 85 bool hasDynParams( const std::vector<ast::ptr<ast::Expr>> & params, const TyVarMap &tyVars, const ast::TypeSubstitution *typeSubs ) { 86 for ( ast::ptr<ast::Expr> const & param : params ) { 87 auto paramType = param.as<ast::TypeExpr>(); 88 assertf( paramType, "Aggregate parameters should be type expressions." ); 89 if ( isDynType( paramType->type, tyVars, typeSubs ) ) { 90 return true; 91 } 92 } 93 return false; 94 } 95 85 96 /// Checks a parameter list for inclusion of polymorphic parameters; will substitute according to env if present 86 97 bool includesPolyParams( std::list< Expression* >& params, const TypeSubstitution *env ) { … … 198 209 } 199 210 return 0; 211 } 212 213 const ast::BaseInstType *isDynType( const ast::Type *type, const TyVarMap &tyVars, const ast::TypeSubstitution *typeSubs ) { 214 type = replaceTypeInst( type, typeSubs ); 215 216 if ( auto inst = dynamic_cast<ast::TypeInstType const *>( type ) ) { 217 auto var = tyVars.find( inst->name ); 218 if ( var != tyVars.end() && var->second.isComplete ) { 219 return inst; 220 } 221 } else if ( auto inst = dynamic_cast<ast::StructInstType const *>( type ) ) { 222 if ( hasDynParams( inst->params, tyVars, typeSubs ) ) { 223 return inst; 224 } 225 } else if ( auto inst = dynamic_cast<ast::UnionInstType const *>( type ) ) { 226 if ( hasDynParams( inst->params, tyVars, typeSubs ) ) { 227 return inst; 228 } 229 } 230 return nullptr; 200 231 } 201 232 … … 378 409 inline D* as( B* p ) { return reinterpret_cast<D*>(p); } 379 410 411 template<typename D, typename B> 412 inline D const * as( B const * p ) { 413 return reinterpret_cast<D const *>( p ); 414 } 415 380 416 /// Flattens a declaration list 381 417 template<typename Output> … … 391 427 for ( Type* ty : src ) { 392 428 ResolvExpr::flatten( ty, out ); 429 } 430 } 431 432 void flattenList( vector<ast::ptr<ast::Type>> const & src, 433 vector<ast::ptr<ast::Type>> & out ) { 434 for ( auto const & type : src ) { 435 ResolvExpr::flatten( type, out ); 393 436 } 394 437 } … … 409 452 // if ( is<VoidType>( aparam->get_type() ) || is<VoidType>( bparam->get_type() ) ) continue; 410 453 if ( ! typesPolyCompatible( aparam->get_type(), bparam->get_type() ) ) return false; 454 } 455 456 return true; 457 } 458 459 bool paramListsPolyCompatible( 460 std::vector<ast::ptr<ast::Expr>> const & lparams, 461 std::vector<ast::ptr<ast::Expr>> const & rparams ) { 462 if ( lparams.size() != rparams.size() ) { 463 return false; 464 } 465 466 for ( auto lparam = lparams.begin(), rparam = rparams.begin() ; 467 lparam != lparams.end() ; ++lparam, ++rparam ) { 468 ast::TypeExpr const * lexpr = lparam->as<ast::TypeExpr>(); 469 assertf( lexpr, "Aggregate parameters should be type expressions" ); 470 ast::TypeExpr const * rexpr = rparam->as<ast::TypeExpr>(); 471 assertf( rexpr, "Aggregate parameters should be type expressions" ); 472 473 // xxx - might need to let VoidType be a wildcard here too; could have some voids 474 // stuffed in for dtype-statics. 475 // if ( is<VoidType>( lexpr->type() ) || is<VoidType>( bparam->get_type() ) ) continue; 476 if ( !typesPolyCompatible( lexpr->type, rexpr->type ) ) { 477 return false; 478 } 411 479 } 412 480 … … 505 573 } 506 574 575 bool typesPolyCompatible( ast::Type const * lhs, ast::Type const * rhs ) { 576 type_index const lid = typeid(*lhs); 577 578 // Polymorphic types always match: 579 if ( type_index(typeid(ast::TypeInstType)) == lid ) return true; 580 581 type_index const rid = typeid(*rhs); 582 if ( type_index(typeid(ast::TypeInstType)) == rid ) return true; 583 584 // All other types only match if they are the same type: 585 if ( lid != rid ) return false; 586 587 // So remaining types can be examined case by case. 588 // Recurse through type structure (conditions borrowed from Unify.cc). 589 590 if ( type_index(typeid(ast::BasicType)) == lid ) { 591 return as<ast::BasicType>(lhs)->kind == as<ast::BasicType>(rhs)->kind; 592 } else if ( type_index(typeid(ast::PointerType)) == lid ) { 593 ast::PointerType const * l = as<ast::PointerType>(lhs); 594 ast::PointerType const * r = as<ast::PointerType>(rhs); 595 596 // void pointers should match any other pointer type. 597 return is<ast::VoidType>( l->base.get() ) 598 || is<ast::VoidType>( r->base.get() ) 599 || typesPolyCompatible( l->base.get(), r->base.get() ); 600 } else if ( type_index(typeid(ast::ReferenceType)) == lid ) { 601 ast::ReferenceType const * l = as<ast::ReferenceType>(lhs); 602 ast::ReferenceType const * r = as<ast::ReferenceType>(rhs); 603 604 // void references should match any other reference type. 605 return is<ast::VoidType>( l->base.get() ) 606 || is<ast::VoidType>( r->base.get() ) 607 || typesPolyCompatible( l->base.get(), r->base.get() ); 608 } else if ( type_index(typeid(ast::ArrayType)) == lid ) { 609 ast::ArrayType const * l = as<ast::ArrayType>(lhs); 610 ast::ArrayType const * r = as<ast::ArrayType>(rhs); 611 612 if ( l->isVarLen ) { 613 if ( !r->isVarLen ) return false; 614 } else { 615 if ( r->isVarLen ) return false; 616 617 auto lc = l->dimension.as<ast::ConstantExpr>(); 618 auto rc = r->dimension.as<ast::ConstantExpr>(); 619 if ( lc && rc && lc->intValue() != rc->intValue() ) { 620 return false; 621 } 622 } 623 624 return typesPolyCompatible( l->base.get(), r->base.get() ); 625 } else if ( type_index(typeid(ast::FunctionType)) == lid ) { 626 ast::FunctionType const * l = as<ast::FunctionType>(lhs); 627 ast::FunctionType const * r = as<ast::FunctionType>(rhs); 628 629 std::vector<ast::ptr<ast::Type>> lparams, rparams; 630 flattenList( l->params, lparams ); 631 flattenList( r->params, rparams ); 632 if ( lparams.size() != rparams.size() ) return false; 633 for ( unsigned i = 0; i < lparams.size(); ++i ) { 634 if ( !typesPolyCompatible( lparams[i], rparams[i] ) ) return false; 635 } 636 637 std::vector<ast::ptr<ast::Type>> lrets, rrets; 638 flattenList( l->returns, lrets ); 639 flattenList( r->returns, rrets ); 640 if ( lrets.size() != rrets.size() ) return false; 641 for ( unsigned i = 0; i < lrets.size(); ++i ) { 642 if ( !typesPolyCompatible( lrets[i], rrets[i] ) ) return false; 643 } 644 return true; 645 } else if ( type_index(typeid(ast::StructInstType)) == lid ) { 646 ast::StructInstType const * l = as<ast::StructInstType>(lhs); 647 ast::StructInstType const * r = as<ast::StructInstType>(rhs); 648 649 if ( l->name != r->name ) return false; 650 return paramListsPolyCompatible( l->params, r->params ); 651 } else if ( type_index(typeid(ast::UnionInstType)) == lid ) { 652 ast::UnionInstType const * l = as<ast::UnionInstType>(lhs); 653 ast::UnionInstType const * r = as<ast::UnionInstType>(rhs); 654 655 if ( l->name != r->name ) return false; 656 return paramListsPolyCompatible( l->params, r->params ); 657 } else if ( type_index(typeid(ast::EnumInstType)) == lid ) { 658 ast::EnumInstType const * l = as<ast::EnumInstType>(lhs); 659 ast::EnumInstType const * r = as<ast::EnumInstType>(rhs); 660 661 return l->name == r->name; 662 } else if ( type_index(typeid(ast::TraitInstType)) == lid ) { 663 ast::TraitInstType const * l = as<ast::TraitInstType>(lhs); 664 ast::TraitInstType const * r = as<ast::TraitInstType>(rhs); 665 666 return l->name == r->name; 667 } else if ( type_index(typeid(ast::TupleType)) == lid ) { 668 ast::TupleType const * l = as<ast::TupleType>(lhs); 669 ast::TupleType const * r = as<ast::TupleType>(rhs); 670 671 std::vector<ast::ptr<ast::Type>> ltypes, rtypes; 672 flattenList( l->types, ( ltypes ) ); 673 flattenList( r->types, ( rtypes ) ); 674 if ( ltypes.size() != rtypes.size() ) return false; 675 676 for ( unsigned i = 0 ; i < ltypes.size() ; ++i ) { 677 if ( !typesPolyCompatible( ltypes[i], rtypes[i] ) ) return false; 678 } 679 return true; 680 // The remaining types (VoidType, VarArgsType, ZeroType & OneType) 681 // have no variation so will always be equal. 682 } else { 683 return true; 684 } 685 } 686 507 687 namespace { 508 688 // temporary hack to avoid re-implementing anything related to TyVarMap -
src/GenPoly/GenPoly.h
rebf8ca5 r23a08aa0 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Jul 22 09:22:57 201713 // Update Count : 711 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 19 16:03:00 2022 13 // Update Count : 8 14 14 // 15 15 … … 27 27 namespace GenPoly { 28 28 29 // TODO Via some tricks this works for ast::TypeDecl::Data as well. 29 30 typedef ErasableScopedMap< std::string, TypeDecl::Data > TyVarMap; 31 30 32 /// Replaces a TypeInstType by its referrent in the environment, if applicable 31 33 Type* replaceTypeInst( Type* type, const TypeSubstitution* env ); … … 41 43 /// returns dynamic-layout type if is dynamic-layout type in tyVars, NULL otherwise; will look up substitution in env if provided 42 44 ReferenceToType *isDynType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 ); 45 const ast::BaseInstType *isDynType( const ast::Type *type, const TyVarMap &tyVars, const ast::TypeSubstitution *typeSubs = 0 ); 43 46 44 47 /// true iff function has dynamic-layout return type under the given type variable map … … 83 86 /// true iff types are structurally identical, where TypeInstType's match any type. 84 87 bool typesPolyCompatible( Type *aty, Type *bty ); 88 bool typesPolyCompatible( ast::Type const * lhs, ast::Type const * rhs ); 85 89 86 90 /// true if arg requires boxing given exprTyVars -
src/GenPoly/InstantiateGeneric.h
rebf8ca5 r23a08aa0 19 19 20 20 class Declaration; 21 namespace ast { 22 class TranslationUnit; 23 } 21 24 22 25 namespace GenPoly { 23 /// Replaces all generic types that have static layout with concrete instantiations. 24 /// Types with concrete values for otype parameters will be template-expanded, while 25 /// dtype and ftype parameters will be replaced by the appropriate void type. 26 void instantiateGeneric( std::list< Declaration* > &translationUnit ); 26 /// Replaces all generic types that have static layout with concrete 27 /// instantiations. Types with concrete values for otype parameters will be 28 /// template-expanded, while dtype and ftype parameters will be replaced by 29 /// the appropriate void type. 30 void instantiateGeneric( std::list< Declaration* > &translationUnit ); 31 void instantiateGeneric( ast::TranslationUnit & translationUnit ); 27 32 } // namespace GenPoly 28 33 -
src/GenPoly/Lvalue2.cc
rebf8ca5 r23a08aa0 23 23 } 24 24 25 26 25 } -
src/GenPoly/ScrubTyVars.cc
rebf8ca5 r23a08aa0 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Mar 16 15:44:27 201713 // Update Count : 311 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 19 16:10:00 2022 13 // Update Count : 4 14 14 // 15 15 16 16 #include <utility> // for pair 17 17 18 #include "AST/Pass.hpp" 18 19 #include "GenPoly.h" // for mangleType, TyVarMap, alignof... 19 20 #include "GenPoly/ErasableScopedMap.h" // for ErasableScopedMap<>::const_it... 20 21 #include "ScrubTyVars.h" 22 #include "SymTab/Mangler.h" // for mangle, typeMode 21 23 #include "SynTree/Declaration.h" // for TypeDecl, TypeDecl::Data, Typ... 22 24 #include "SynTree/Expression.h" // for Expression (ptr only), NameExpr … … 112 114 return pointer; 113 115 } 116 117 namespace { 118 119 enum class ScrubMode { 120 FromMap, 121 DynamicFromMap, 122 All, 123 }; 124 125 struct ScrubTypeVars : 126 public ast::WithGuards, 127 public ast::WithShortCircuiting, 128 public ast::WithVisitorRef<ScrubTypeVars> { 129 130 ScrubTypeVars( ScrubMode m, TyVarMap const * tv ) : 131 mode ( m ), typeVars( tv ) {} 132 133 void previsit( ast::TypeInstType const * ) { visit_children = false; } 134 void previsit( ast::StructInstType const * ) { visit_children = false; } 135 void previsit( ast::UnionInstType const * ) { visit_children = false; } 136 void previsit( ast::SizeofExpr const * expr ) { primeBaseScrub( expr->type ); } 137 void previsit( ast::AlignofExpr const * expr ) { primeBaseScrub( expr->type ); } 138 void previsit( ast::PointerType const * type ) { primeBaseScrub( type->base ); } 139 140 ast::Type const * postvisit( ast::TypeInstType const * type ); 141 ast::Type const * postvisit( ast::StructInstType const * type ); 142 ast::Type const * postvisit( ast::UnionInstType const * type ); 143 ast::Expr const * postvisit( ast::SizeofExpr const * expr ); 144 ast::Expr const * postvisit( ast::AlignofExpr const * expr ); 145 ast::Type const * postvisit( ast::PointerType const * type ); 146 147 private: 148 ScrubMode const mode; 149 /// Type varriables to scrub. 150 TyVarMap const * const typeVars; 151 /// Value cached by primeBaseScrub. 152 ast::Type const * dynType = nullptr; 153 154 /// Returns the type if it should be scrubbed, nullptr otherwise. 155 ast::Type const * shouldScrub( ast::Type const * type ) { 156 switch ( mode ) { 157 case ScrubMode::FromMap: 158 return isPolyType( type, *typeVars ); 159 case ScrubMode::DynamicFromMap: 160 return isDynType( type, *typeVars ); 161 case ScrubMode::All: 162 return isPolyType( type ); 163 default: 164 assertf( false, "Invalid ScrubMode in shouldScrub." ); 165 throw; 166 } 167 } 168 169 void primeBaseScrub( ast::Type const * type ) { 170 // Need to determine whether type needs to be scrubbed to 171 // determine whether automatic recursion is necessary. 172 if ( ast::Type const * t = shouldScrub( type ) ) { 173 visit_children = false; 174 GuardValue( dynType ) = t; 175 } 176 } 177 178 ast::Type const * postvisitAggregateType( 179 ast::BaseInstType const * type ) { 180 if ( !shouldScrub( type ) ) return type; 181 return new ast::PointerType( new ast::VoidType( type->qualifiers ) ); 182 } 183 }; 184 185 ast::Type const * ScrubTypeVars::postvisit( ast::TypeInstType const * type ) { 186 // This implies that mode == ScrubMode::All. 187 if ( !typeVars ) { 188 if ( ast::TypeDecl::Ftype == type->kind ) { 189 return new ast::PointerType( 190 new ast::FunctionType( ast::FixedArgs ) ); 191 } else { 192 return new ast::PointerType( 193 new ast::VoidType( type->qualifiers ) ); 194 } 195 } 196 197 auto typeVar = typeVars->find( type->name ); 198 if ( typeVar == typeVars->end() ) { 199 return type; 200 } 201 202 switch ( typeVar->second.kind ) { 203 case ast::TypeDecl::Dtype: 204 case ast::TypeDecl::Ttype: 205 return new ast::PointerType( 206 new ast::VoidType( type->qualifiers ) ); 207 case ast::TypeDecl::Ftype: 208 return new ast::PointerType( 209 new ast::FunctionType( ast::VariableArgs ) ); 210 default: 211 assertf( false, 212 "Unhandled type variable kind: %d", typeVar->second.kind ); 213 throw; // Just in case the assert is removed, stop here. 214 } 215 } 216 217 ast::Type const * ScrubTypeVars::postvisit( ast::StructInstType const * type ) { 218 return postvisitAggregateType( type ); 219 } 220 221 ast::Type const * ScrubTypeVars::postvisit( ast::UnionInstType const * type ) { 222 return postvisitAggregateType( type ); 223 } 224 225 ast::Expr const * ScrubTypeVars::postvisit( ast::SizeofExpr const * expr ) { 226 // sizeof( T ) becomes the _sizeof_T parameter. 227 if ( dynType ) { 228 return new ast::NameExpr( expr->location, 229 sizeofName( Mangle::mangle( dynType, Mangle::typeMode() ) ) ); 230 } else { 231 return expr; 232 } 233 } 234 235 ast::Expr const * ScrubTypeVars::postvisit( ast::AlignofExpr const * expr ) { 236 // alignof( T ) becomes the _alignof_T parameter. 237 if ( dynType ) { 238 return new ast::NameExpr( expr->location, 239 alignofName( Mangle::mangle( dynType, Mangle::typeMode() ) ) ); 240 } else { 241 return expr; 242 } 243 } 244 245 ast::Type const * ScrubTypeVars::postvisit( ast::PointerType const * type ) { 246 if ( dynType ) { 247 ast::Type * ret = ast::mutate( dynType->accept( *visitor ) ); 248 ret->qualifiers |= type->qualifiers; 249 return ret; 250 } else { 251 return type; 252 } 253 } 254 255 const ast::Node * scrubTypeVarsBase( 256 const ast::Node * target, 257 ScrubMode mode, const TyVarMap * typeVars ) { 258 if ( ScrubMode::All == mode ) { 259 assert( nullptr == typeVars ); 260 } else { 261 assert( nullptr != typeVars ); 262 } 263 ast::Pass<ScrubTypeVars> visitor( mode, typeVars ); 264 return target->accept( visitor ); 265 } 266 267 } // namespace 268 269 template<> 270 ast::Node const * scrubAllTypeVars<ast::Node>( const ast::Node * target ) { 271 return scrubTypeVarsBase( target, ScrubMode::All, nullptr ); 272 } 273 114 274 } // namespace GenPoly 115 275 -
src/GenPoly/ScrubTyVars.h
rebf8ca5 r23a08aa0 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Jul 22 09:21:47 201713 // Update Count : 211 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 19 14:14:00 2022 13 // Update Count : 3 14 14 // 15 15 … … 18 18 #include <cassert> // for assert 19 19 20 #include "AST/Fwd.hpp" // for Node 20 21 #include "Common/PassVisitor.h" 21 22 #include "GenPoly.h" // for TyVarMap, isPolyType, isDynType … … 108 109 } 109 110 111 /// For all polymorphic types, replaces generic types, with the appropriate 112 /// void type, and sizeof/alignof expressions with the proper variable. 113 template<typename node_t> 114 node_t const * scrubAllTypeVars( node_t const * target ) { 115 return strict_dynamic_cast<node_t const *>( scrubAllTypeVars<ast::Node>( target ) ); 116 } 117 118 template<> 119 ast::Node const * scrubAllTypeVars<ast::Node>( const ast::Node * target ); 120 110 121 } // namespace GenPoly 111 122 -
src/GenPoly/SpecializeNew.cpp
rebf8ca5 r23a08aa0 240 240 } 241 241 242 namespace { 243 struct TypeInstFixer : public ast::WithShortCircuiting { 244 std::map<const ast::TypeDecl *, std::pair<int, int>> typeMap; 245 246 void previsit(const ast::TypeDecl *) { visit_children = false; } 247 const ast::TypeInstType * postvisit(const ast::TypeInstType * typeInst) { 248 if (typeMap.count(typeInst->base)) { 249 ast::TypeInstType * newInst = mutate(typeInst); 250 auto const & pair = typeMap[typeInst->base]; 251 newInst->expr_id = pair.first; 252 newInst->formal_usage = pair.second; 253 return newInst; 254 } 255 return typeInst; 256 } 257 }; 258 } 242 struct TypeInstFixer final : public ast::WithShortCircuiting { 243 std::map<const ast::TypeDecl *, std::pair<int, int>> typeMap; 244 245 void previsit(const ast::TypeDecl *) { visit_children = false; } 246 const ast::TypeInstType * postvisit(const ast::TypeInstType * typeInst) { 247 if (typeMap.count(typeInst->base)) { 248 ast::TypeInstType * newInst = mutate(typeInst); 249 auto const & pair = typeMap[typeInst->base]; 250 newInst->expr_id = pair.first; 251 newInst->formal_usage = pair.second; 252 return newInst; 253 } 254 return typeInst; 255 } 256 }; 259 257 260 258 const ast::Expr * SpecializeCore::createThunkFunction( -
src/GenPoly/module.mk
rebf8ca5 r23a08aa0 27 27 GenPoly/FindFunction.cc \ 28 28 GenPoly/FindFunction.h \ 29 GenPoly/InstantiateGenericNew.cpp \ 29 30 GenPoly/InstantiateGeneric.cc \ 30 31 GenPoly/InstantiateGeneric.h \ -
src/InitTweak/InitTweak.cc
rebf8ca5 r23a08aa0 1241 1241 static const char * const tlsd_section = ".tdata" ASM_COMMENT; 1242 1242 void addDataSectionAttribute( ObjectDecl * objDecl ) { 1243 const bool is_tls = objDecl->get_storageClasses().is_threadlocal ;1243 const bool is_tls = objDecl->get_storageClasses().is_threadlocal_any(); 1244 1244 const char * section = is_tls ? tlsd_section : data_section; 1245 1245 objDecl->attributes.push_back(new Attribute("section", { … … 1249 1249 1250 1250 void addDataSectionAttribute( ast::ObjectDecl * objDecl ) { 1251 const bool is_tls = objDecl->storage.is_threadlocal ;1251 const bool is_tls = objDecl->storage.is_threadlocal_any(); 1252 1252 const char * section = is_tls ? tlsd_section : data_section; 1253 1253 objDecl->attributes.push_back(new ast::Attribute("section", { -
src/Makefile.am
rebf8ca5 r23a08aa0 71 71 EXTRA_DIST = include/cassert include/optional BasicTypes-gen.cc 72 72 73 AM_CXXFLAGS = @HOST_FLAGS@ -Wno-deprecated -Wall -Wextra -Werror=return-type -DDEBUG_ALL -I./Parser -I$(srcdir)/Parser -I$(srcdir)/include -DYY_NO_INPUT -O3 -g -std=c++1 4$(TCMALLOCFLAG)73 AM_CXXFLAGS = @HOST_FLAGS@ -Wno-deprecated -Wall -Wextra -Werror=return-type -DDEBUG_ALL -I./Parser -I$(srcdir)/Parser -I$(srcdir)/include -DYY_NO_INPUT -O3 -g -std=c++17 $(TCMALLOCFLAG) 74 74 AM_LDFLAGS = @HOST_FLAGS@ -Xlinker -export-dynamic 75 75 ARFLAGS = cr -
src/Parser/DeclarationNode.cc
rebf8ca5 r23a08aa0 262 262 newnode->type->enumeration.anon = name == nullptr; 263 263 if ( base && base->type) { 264 newnode->type->base = base->type; 264 newnode->type->base = base->type; 265 265 } // if 266 266 … … 505 505 } // for 506 506 // src is the new item being added and has a single bit 507 } else if ( ! src->storageClasses.is_threadlocal ) { // conflict ?507 } else if ( ! src->storageClasses.is_threadlocal_any() ) { // conflict ? 508 508 appendError( error, string( "conflicting " ) + Type::StorageClassesNames[storageClasses.ffs()] + 509 509 " & " + Type::StorageClassesNames[src->storageClasses.ffs()] ); -
src/Parser/lex.ll
rebf8ca5 r23a08aa0 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Sun Jun 20 18:41:09 202113 * Update Count : 7 5912 * Last Modified On : Tue Aug 30 18:39:54 2022 13 * Update Count : 760 14 14 */ 15 15 … … 314 314 switch { KEYWORD_RETURN(SWITCH); } 315 315 thread { KEYWORD_RETURN(THREAD); } // C11 316 _Thread_local { KEYWORD_RETURN(THREADLOCAL); } // C11 316 __thread { KEYWORD_RETURN(THREADLOCALGCC); } // GCC 317 _Thread_local { KEYWORD_RETURN(THREADLOCALC11); } // C11 317 318 throw { KEYWORD_RETURN(THROW); } // CFA 318 319 throwResume { KEYWORD_RETURN(THROWRESUME); } // CFA -
src/Parser/parser.yy
rebf8ca5 r23a08aa0 58 58 59 59 // lex uses __null in a boolean context, it's fine. 60 //#pragma GCC diagnostic ignored "-Wparentheses-equality" 60 #pragma GCC diagnostic ignored "-Wpragmas" 61 #pragma GCC diagnostic ignored "-Wparentheses-equality" 62 #pragma GCC diagnostic warning "-Wpragmas" 61 63 62 64 extern DeclarationNode * parseTree; … … 293 295 %token TYPEDEF 294 296 %token EXTERN STATIC AUTO REGISTER 295 %token THREADLOCAL //C11297 %token THREADLOCALGCC THREADLOCALC11 // GCC, C11 296 298 %token INLINE FORTRAN // C99, extension ISO/IEC 9899:1999 Section J.5.9(1) 297 299 %token NORETURN // C11 … … 1345 1347 { 1346 1348 if ( $2 == OperKinds::LThan || $2 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1347 else { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1349 else { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1348 1350 } 1349 1351 | comma_expression updowneq comma_expression '~' comma_expression // CFA, anonymous loop-index … … 1357 1359 { 1358 1360 if ( $2 == OperKinds::LThan || $2 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1359 else { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1361 else { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1360 1362 } 1361 1363 | comma_expression updowneq comma_expression '~' '@' // CFA, error … … 2082 2084 | REGISTER 2083 2085 { $$ = DeclarationNode::newStorageClass( Type::Register ); } 2084 | THREADLOCAL // C11 2085 { $$ = DeclarationNode::newStorageClass( Type::Threadlocal ); } 2086 | THREADLOCALGCC // GCC 2087 { $$ = DeclarationNode::newStorageClass( Type::ThreadlocalGcc ); } 2088 | THREADLOCALC11 // C11 2089 { $$ = DeclarationNode::newStorageClass( Type::ThreadlocalC11 ); } 2086 2090 // Put function specifiers here to simplify parsing rules, but separate them semantically. 2087 2091 | INLINE // C99 -
src/ResolvExpr/CandidateFinder.cpp
rebf8ca5 r23a08aa0 269 269 unsigned nextArg, unsigned tupleStart = 0, Cost cost = Cost::zero, 270 270 unsigned nextExpl = 0, unsigned explAlt = 0 ) 271 : parent(parent), expr( expr ), cost( cost ), env( move( env ) ), need(move( need ) ),272 have( move( have ) ), open(move( open ) ), nextArg( nextArg ), tupleStart( tupleStart ),271 : parent(parent), expr( expr ), cost( cost ), env( std::move( env ) ), need( std::move( need ) ), 272 have( std::move( have ) ), open( std::move( open ) ), nextArg( nextArg ), tupleStart( tupleStart ), 273 273 nextExpl( nextExpl ), explAlt( explAlt ) {} 274 274 … … 276 276 const ArgPack & o, ast::TypeEnvironment && env, ast::AssertionSet && need, 277 277 ast::AssertionSet && have, ast::OpenVarSet && open, unsigned nextArg, Cost added ) 278 : parent( o.parent ), expr( o.expr ), cost( o.cost + added ), env( move( env ) ),279 need( move( need ) ), have( move( have ) ), open(move( open ) ), nextArg( nextArg ),278 : parent( o.parent ), expr( o.expr ), cost( o.cost + added ), env( std::move( env ) ), 279 need( std::move( need ) ), have( std::move( have ) ), open( std::move( open ) ), nextArg( nextArg ), 280 280 tupleStart( o.tupleStart ), nextExpl( 0 ), explAlt( 0 ) {} 281 281 … … 301 301 // reset pack to appropriate tuple 302 302 std::vector< ast::ptr< ast::Expr > > exprv( exprs.begin(), exprs.end() ); 303 expr = new ast::TupleExpr{ expr->location, move( exprv ) };303 expr = new ast::TupleExpr{ expr->location, std::move( exprv ) }; 304 304 tupleStart = pack->tupleStart - 1; 305 305 parent = pack->parent; … … 404 404 newResult.open, symtab ) 405 405 ) { 406 finalResults.emplace_back( move( newResult ) );406 finalResults.emplace_back( std::move( newResult ) ); 407 407 } 408 408 … … 423 423 if ( expl.exprs.empty() ) { 424 424 results.emplace_back( 425 results[i], move( env ), copy( results[i].need ),426 copy( results[i].have ), move( open ), nextArg + 1, expl.cost );425 results[i], std::move( env ), copy( results[i].need ), 426 copy( results[i].have ), std::move( open ), nextArg + 1, expl.cost ); 427 427 428 428 continue; … … 431 431 // add new result 432 432 results.emplace_back( 433 i, expl.exprs.front(), move( env ), copy( results[i].need ),434 copy( results[i].have ), move( open ), nextArg + 1, nTuples,433 i, expl.exprs.front(), std::move( env ), copy( results[i].need ), 434 copy( results[i].have ), std::move( open ), nextArg + 1, nTuples, 435 435 expl.cost, expl.exprs.size() == 1 ? 0 : 1, j ); 436 436 } … … 444 444 // splice final results onto results 445 445 for ( std::size_t i = 0; i < finalResults.size(); ++i ) { 446 results.emplace_back( move( finalResults[i] ) );446 results.emplace_back( std::move( finalResults[i] ) ); 447 447 } 448 448 return ! finalResults.empty(); … … 478 478 479 479 results.emplace_back( 480 i, expr, move( env ), move( need ), move( have ),move( open ), nextArg,480 i, expr, std::move( env ), std::move( need ), std::move( have ), std::move( open ), nextArg, 481 481 nTuples, Cost::zero, nextExpl, results[i].explAlt ); 482 482 } … … 494 494 if ( unify( paramType, cnst->result, env, need, have, open, symtab ) ) { 495 495 results.emplace_back( 496 i, new ast::DefaultArgExpr{ cnst->location, cnst }, move( env ),497 move( need ), move( have ),move( open ), nextArg, nTuples );496 i, new ast::DefaultArgExpr{ cnst->location, cnst }, std::move( env ), 497 std::move( need ), std::move( have ), std::move( open ), nextArg, nTuples ); 498 498 } 499 499 } … … 516 516 if ( expl.exprs.empty() ) { 517 517 results.emplace_back( 518 results[i], move( env ), move( need ), move( have ),move( open ),518 results[i], std::move( env ), std::move( need ), std::move( have ), std::move( open ), 519 519 nextArg + 1, expl.cost ); 520 520 … … 538 538 // add new result 539 539 results.emplace_back( 540 i, expr, move( env ), move( need ), move( have ),move( open ),540 i, expr, std::move( env ), std::move( need ), std::move( have ), std::move( open ), 541 541 nextArg + 1, nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j ); 542 542 } … … 576 576 restructureCast( idx, toType->getComponent( i ), isGenerated ) ); 577 577 } 578 return new ast::TupleExpr{ arg->location, move( components ) };578 return new ast::TupleExpr{ arg->location, std::move( components ) }; 579 579 } else { 580 580 // handle normally … … 672 672 } 673 673 std::vector< ast::ptr< ast::Expr > > vargs( args.begin(), args.end() ); 674 appExpr->args = move( vargs );674 appExpr->args = std::move( vargs ); 675 675 // build and validate new candidate 676 676 auto newCand = … … 783 783 if ( expl.exprs.empty() ) { 784 784 results.emplace_back( 785 results[i], move( env ), copy( results[i].need ),786 copy( results[i].have ), move( open ), nextArg + 1,785 results[i], std::move( env ), copy( results[i].need ), 786 copy( results[i].have ), std::move( open ), nextArg + 1, 787 787 expl.cost ); 788 788 … … 792 792 // add new result 793 793 results.emplace_back( 794 i, expl.exprs.front(), move( env ), copy( results[i].need ),795 copy( results[i].have ), move( open ), nextArg + 1, 0, expl.cost,794 i, expl.exprs.front(), std::move( env ), copy( results[i].need ), 795 copy( results[i].have ), std::move( open ), nextArg + 1, 0, expl.cost, 796 796 expl.exprs.size() == 1 ? 0 : 1, j ); 797 797 } … … 843 843 // as a member expression 844 844 addAnonConversions( newCand ); 845 candidates.emplace_back( move( newCand ) );845 candidates.emplace_back( std::move( newCand ) ); 846 846 } 847 847 } … … 901 901 const ast::EnumDecl * enumDecl = enumInst->base; 902 902 if ( const ast::Type* enumType = enumDecl->base ) { 903 // instance of enum (T) is a instance of type (T) 903 // instance of enum (T) is a instance of type (T) 904 904 funcFinder.otypeKeys.insert(Mangle::mangle(enumType, Mangle::NoGenericParams | Mangle::Type)); 905 905 } else { … … 907 907 funcFinder.otypeKeys.insert(Mangle::mangle(enumDecl, Mangle::NoGenericParams | Mangle::Type)); 908 908 } 909 } 909 } 910 910 else funcFinder.otypeKeys.insert(Mangle::mangle(argType, Mangle::NoGenericParams | Mangle::Type)); 911 911 } … … 986 986 funcE.emplace_back( *func, symtab ); 987 987 } 988 argExpansions.emplace_front( move( funcE ) );988 argExpansions.emplace_front( std::move( funcE ) ); 989 989 990 990 for ( const CandidateRef & op : opFinder ) { … … 1030 1030 if ( cvtCost != Cost::infinity ) { 1031 1031 withFunc->cvtCost = cvtCost; 1032 candidates.emplace_back( move( withFunc ) );1033 } 1034 } 1035 found = move( candidates );1032 candidates.emplace_back( std::move( withFunc ) ); 1033 } 1034 } 1035 found = std::move( candidates ); 1036 1036 1037 1037 // use a new list so that candidates are not examined by addAnonConversions twice … … 1131 1131 CandidateRef newCand = std::make_shared<Candidate>( 1132 1132 restructureCast( cand->expr, toType, castExpr->isGenerated ), 1133 copy( cand->env ), move( open ),move( need ), cand->cost,1133 copy( cand->env ), std::move( open ), std::move( need ), cand->cost, 1134 1134 cand->cost + thisCost ); 1135 1135 inferParameters( newCand, matches ); … … 1285 1285 // as a name expression 1286 1286 addAnonConversions( newCand ); 1287 candidates.emplace_back( move( newCand ) );1287 candidates.emplace_back( std::move( newCand ) ); 1288 1288 } 1289 1289 } … … 1394 1394 new ast::LogicalExpr{ 1395 1395 logicalExpr->location, r1->expr, r2->expr, logicalExpr->isAnd }, 1396 move( env ), move( open ),move( need ), r1->cost + r2->cost );1396 std::move( env ), std::move( open ), std::move( need ), r1->cost + r2->cost ); 1397 1397 } 1398 1398 } … … 1452 1452 // output candidate 1453 1453 CandidateRef newCand = std::make_shared<Candidate>( 1454 newExpr, move( env ), move( open ),move( need ), cost );1454 newExpr, std::move( env ), std::move( open ), std::move( need ), cost ); 1455 1455 inferParameters( newCand, candidates ); 1456 1456 } … … 1519 1519 // add candidate 1520 1520 CandidateRef newCand = std::make_shared<Candidate>( 1521 newExpr, move( env ), move( open ),move( need ),1521 newExpr, std::move( env ), std::move( open ), std::move( need ), 1522 1522 r1->cost + r2->cost ); 1523 1523 inferParameters( newCand, candidates ); … … 1548 1548 1549 1549 addCandidate( 1550 new ast::TupleExpr{ tupleExpr->location, move( exprs ) },1551 move( env ), move( open ),move( need ), sumCost( subs ) );1550 new ast::TupleExpr{ tupleExpr->location, std::move( exprs ) }, 1551 std::move( env ), std::move( open ), std::move( need ), sumCost( subs ) ); 1552 1552 } 1553 1553 } … … 1635 1635 initExpr->location, restructureCast( cand->expr, toType ), 1636 1636 initAlt.designation }, 1637 move(env), move( open ),move( need ), cand->cost, thisCost );1637 std::move(env), std::move( open ), std::move( need ), cand->cost, thisCost ); 1638 1638 inferParameters( newCand, matches ); 1639 1639 } … … 1768 1768 cand->env.applyFree( newResult ); 1769 1769 cand->expr = ast::mutate_field( 1770 cand->expr.get(), &ast::Expr::result, move( newResult ) );1770 cand->expr.get(), &ast::Expr::result, std::move( newResult ) ); 1771 1771 1772 1772 out.emplace_back( cand ); … … 1854 1854 1855 1855 auto oldsize = candidates.size(); 1856 candidates = move( pruned );1856 candidates = std::move( pruned ); 1857 1857 1858 1858 PRINT( -
src/SynTree/Statement.cc
rebf8ca5 r23a08aa0 105 105 }; 106 106 107 BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticErrorException ):107 BranchStmt::BranchStmt( Label target, Type type ) : 108 108 Statement(), originalTarget( target ), target( target ), computedTarget( nullptr ), type( type ) { 109 109 //actually this is a syntactic error signaled by the parser … … 113 113 } 114 114 115 BranchStmt::BranchStmt( Expression * computedTarget, Type type ) throw ( SemanticErrorException ):115 BranchStmt::BranchStmt( Expression * computedTarget, Type type ) : 116 116 Statement(), computedTarget( computedTarget ), type( type ) { 117 117 if ( type != BranchStmt::Goto || computedTarget == nullptr ) { … … 211 211 } 212 212 213 CaseStmt::CaseStmt( Expression * condition, const list<Statement *> & statements, bool deflt ) throw ( SemanticErrorException ):213 CaseStmt::CaseStmt( Expression * condition, const list<Statement *> & statements, bool deflt ) : 214 214 Statement(), condition( condition ), stmts( statements ), _isDefault( deflt ) { 215 215 if ( isDefault() && condition != nullptr ) SemanticError( condition, "default case with condition: " ); … … 575 575 } 576 576 577 MutexStmt::MutexStmt( Statement * stmt, const list<Expression *> mutexObjs ) 577 MutexStmt::MutexStmt( Statement * stmt, const list<Expression *> mutexObjs ) 578 578 : Statement(), stmt( stmt ), mutexObjs( mutexObjs ) { } 579 579 -
src/SynTree/Statement.h
rebf8ca5 r23a08aa0 200 200 std::list<Statement *> stmts; 201 201 202 CaseStmt( Expression * conditions, const std::list<Statement *> & stmts, bool isdef = false ) throw (SemanticErrorException);202 CaseStmt( Expression * conditions, const std::list<Statement *> & stmts, bool isdef = false ); 203 203 CaseStmt( const CaseStmt & other ); 204 204 virtual ~CaseStmt(); … … 289 289 Type type; 290 290 291 BranchStmt( Label target, Type ) throw (SemanticErrorException);292 BranchStmt( Expression * computedTarget, Type ) throw (SemanticErrorException);291 BranchStmt( Label target, Type ); 292 BranchStmt( Expression * computedTarget, Type ); 293 293 294 294 Label get_originalTarget() { return originalTarget; } -
src/SynTree/Type.cc
rebf8ca5 r23a08aa0 80 80 // These must remain in the same order as the corresponding bit fields. 81 81 const char * Type::FuncSpecifiersNames[] = { "inline", "_Noreturn", "fortran" }; 82 const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "_ Thread_local" };82 const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "__thread", "_Thread_local" }; 83 83 const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "mutex", "_Atomic" }; 84 84 -
src/SynTree/Type.h
rebf8ca5 r23a08aa0 84 84 }; // FuncSpecifiers 85 85 86 enum { Extern = 1 << 0, Static = 1 << 1, Auto = 1 << 2, Register = 1 << 3, Threadlocal = 1 << 4, NumStorageClass = 5};86 enum { Extern = 1 << 0, Static = 1 << 1, Auto = 1 << 2, Register = 1 << 3, ThreadlocalGcc = 1 << 4, ThreadlocalC11 = 1 << 5, NumStorageClass = 6 }; 87 87 static const char * StorageClassesNames[]; 88 88 union StorageClasses { … … 93 93 bool is_auto : 1; 94 94 bool is_register : 1; 95 bool is_threadlocal : 1; 95 bool is_threadlocalGcc : 1; 96 bool is_threadlocalC11 : 1; 96 97 }; 97 98 … … 100 101 // equality (==, !=) works implicitly on first field "val", relational operations are undefined. 101 102 BFCommon( StorageClasses, NumStorageClass ) 103 104 bool is_threadlocal_any() { return this->is_threadlocalC11 || this->is_threadlocalGcc; } 102 105 }; // StorageClasses 103 106 -
src/Tuples/TupleExpansionNew.cpp
rebf8ca5 r23a08aa0 101 101 102 102 /// Replaces Tuple Assign & Index Expressions, and Tuple Types. 103 struct TupleMainExpander :103 struct TupleMainExpander final : 104 104 public ast::WithGuards, 105 105 public ast::WithVisitorRef<TupleMainExpander>, … … 254 254 } 255 255 256 struct TupleExprExpander {256 struct TupleExprExpander final { 257 257 ast::Expr const * postvisit( ast::TupleExpr const * expr ) { 258 258 return replaceTupleExpr( expr->location, -
src/Virtual/ExpandCasts.cc
rebf8ca5 r23a08aa0 317 317 }; 318 318 319 struct ExpandCastsCore {319 struct ExpandCastsCore final { 320 320 void previsit( ast::FunctionDecl const * decl ); 321 321 void previsit( ast::StructDecl const * decl ); … … 362 362 } 363 363 364 /// Copy newType, but give the copy the params of the oldType. 364 365 ast::StructInstType * polyCopy( 365 366 ast::StructInstType const * oldType, -
src/config.h.in
rebf8ca5 r23a08aa0 27 27 /* Location of cfa install. */ 28 28 #undef CFA_PREFIX 29 30 /* Sets whether or not to use the new-ast, this is adefault value and can be31 overrided by --old-ast and --new-ast */32 #undef CFA_USE_NEW_AST33 29 34 30 /* Major.Minor */ -
src/main.cc
rebf8ca5 r23a08aa0 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thu 11 12:18:00 202213 // Update Count : 67 712 // Last Modified On : Thu Sep 15 13:58:00 2022 13 // Update Count : 678 14 14 // 15 15 … … 38 38 #include "CodeGen/Generate.h" // for generate 39 39 #include "CodeGen/LinkOnce.h" // for translateLinkOnce 40 #include "CodeTools/DeclStats.h" // for printDeclStats41 #include "CodeTools/ResolvProtoDump.h" // for dumpAsResolvProto42 40 #include "CodeTools/TrackLoc.h" // for fillLocations 43 41 #include "Common/CodeLocationTools.hpp" // for forceFillCodeLocations … … 45 43 #include "Common/DeclStats.hpp" // for printDeclStats 46 44 #include "Common/ResolvProtoDump.hpp" // for dumpAsResolverProto 47 #include "Common/Stats.h" 48 #include "Common/PassVisitor.h" 49 #include "Common/SemanticError.h" // for SemanticError 45 #include "Common/Stats.h" // for Stats 50 46 #include "Common/UnimplementedError.h" // for UnimplementedError 51 47 #include "Common/utility.h" // for deleteAll, filter, printAll … … 53 49 #include "Concurrency/Waitfor.h" // for generateWaitfor 54 50 #include "ControlStruct/ExceptDecl.h" // for translateExcept 55 #include "ControlStruct/ExceptTranslate.h" // for translate EHM51 #include "ControlStruct/ExceptTranslate.h" // for translateThrows, translat... 56 52 #include "ControlStruct/FixLabels.hpp" // for fixLabels 57 53 #include "ControlStruct/HoistControlDecls.hpp" // hoistControlDecls 58 #include "ControlStruct/Mutate.h" // for mutate59 54 #include "GenPoly/Box.h" // for box 60 55 #include "GenPoly/InstantiateGeneric.h" // for instantiateGeneric … … 66 61 #include "Parser/ParseNode.h" // for DeclarationNode, buildList 67 62 #include "Parser/TypedefTable.h" // for TypedefTable 68 #include "ResolvExpr/AlternativePrinter.h" // for AlternativePrinter69 63 #include "ResolvExpr/CandidatePrinter.hpp" // for printCandidates 70 64 #include "ResolvExpr/Resolver.h" // for resolve 71 #include "SymTab/Validate.h" // for validate72 #include "SymTab/ValidateType.h" // for linkReferenceToTypes73 65 #include "SynTree/LinkageSpec.h" // for Spec, Cforall, Intrinsic 74 66 #include "SynTree/Declaration.h" // for Declaration 75 #include "SynTree/Visitor.h" // for acceptAll76 67 #include "Tuples/Tuples.h" // for expandMemberTuples, expan... 77 68 #include "Validate/Autogen.hpp" // for autogenerateRoutines … … 330 321 Stats::Time::StopBlock(); 331 322 332 if( useNewAST ) { 333 if (Stats::Counters::enabled) { 334 ast::pass_visitor_stats.avg = Stats::Counters::build<Stats::Counters::AverageCounter<double>>("Average Depth - New"); 335 ast::pass_visitor_stats.max = Stats::Counters::build<Stats::Counters::MaxCounter<double>>("Max depth - New"); 336 } 337 auto transUnit = convert( move( translationUnit ) ); 338 339 forceFillCodeLocations( transUnit ); 340 341 PASS( "Translate Exception Declarations", ControlStruct::translateExcept( transUnit ) ); 342 if ( exdeclp ) { 343 dump( move( transUnit ) ); 344 return EXIT_SUCCESS; 345 } 346 347 PASS( "Verify Ctor, Dtor & Assign", Validate::verifyCtorDtorAssign( transUnit ) ); 348 PASS( "Hoist Type Decls", Validate::hoistTypeDecls( transUnit ) ); 349 // Hoist Type Decls pulls some declarations out of contexts where 350 // locations are not tracked. Perhaps they should be, but for now 351 // the full fill solves it. 352 forceFillCodeLocations( transUnit ); 353 354 PASS( "Replace Typedefs", Validate::replaceTypedef( transUnit ) ); 355 PASS( "Fix Return Types", Validate::fixReturnTypes( transUnit ) ); 356 PASS( "Enum and Pointer Decay", Validate::decayEnumsAndPointers( transUnit ) ); 357 358 PASS( "Link Reference To Types", Validate::linkReferenceToTypes( transUnit ) ); 359 360 PASS( "Fix Qualified Types", Validate::fixQualifiedTypes( transUnit ) ); 361 PASS( "Hoist Struct", Validate::hoistStruct( transUnit ) ); 362 PASS( "Eliminate Typedef", Validate::eliminateTypedef( transUnit ) ); 363 PASS( "Validate Generic Parameters", Validate::fillGenericParameters( transUnit ) ); 364 PASS( "Translate Dimensions", Validate::translateDimensionParameters( transUnit ) ); 365 PASS( "Check Function Returns", Validate::checkReturnStatements( transUnit ) ); 366 PASS( "Fix Return Statements", InitTweak::fixReturnStatements( transUnit ) ); 367 PASS( "Implement Concurrent Keywords", Concurrency::implementKeywords( transUnit ) ); 368 PASS( "Forall Pointer Decay", Validate::decayForallPointers( transUnit ) ); 369 PASS( "Hoist Control Declarations", ControlStruct::hoistControlDecls( transUnit ) ); 370 371 PASS( "Generate Autogen Routines", Validate::autogenerateRoutines( transUnit ) ); 372 373 PASS( "Implement Mutex", Concurrency::implementMutex( transUnit ) ); 374 PASS( "Implement Thread Start", Concurrency::implementThreadStarter( transUnit ) ); 375 PASS( "Compound Literal", Validate::handleCompoundLiterals( transUnit ) ); 376 PASS( "Set Length From Initializer", Validate::setLengthFromInitializer( transUnit ) ); 377 PASS( "Find Global Decls", Validate::findGlobalDecls( transUnit ) ); 378 PASS( "Fix Label Address", Validate::fixLabelAddresses( transUnit ) ); 379 380 if ( symtabp ) { 381 return EXIT_SUCCESS; 382 } // if 383 384 if ( expraltp ) { 385 ResolvExpr::printCandidates( transUnit ); 386 return EXIT_SUCCESS; 387 } // if 388 389 if ( validp ) { 390 dump( move( transUnit ) ); 391 return EXIT_SUCCESS; 392 } // if 393 394 PASS( "Translate Throws", ControlStruct::translateThrows( transUnit ) ); 395 PASS( "Fix Labels", ControlStruct::fixLabels( transUnit ) ); 396 PASS( "Fix Names", CodeGen::fixNames( transUnit ) ); 397 PASS( "Gen Init", InitTweak::genInit( transUnit ) ); 398 PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( transUnit ) ); 399 400 if ( libcfap ) { 401 // Generate the bodies of cfa library functions. 402 LibCfa::makeLibCfa( transUnit ); 403 } // if 404 405 if ( declstatsp ) { 406 printDeclStats( transUnit ); 407 return EXIT_SUCCESS; 408 } // if 409 410 if ( bresolvep ) { 411 dump( move( transUnit ) ); 412 return EXIT_SUCCESS; 413 } // if 414 415 if ( resolvprotop ) { 416 dumpAsResolverProto( transUnit ); 417 return EXIT_SUCCESS; 418 } // if 419 420 PASS( "Resolve", ResolvExpr::resolve( transUnit ) ); 421 if ( exprp ) { 422 dump( move( transUnit ) ); 423 return EXIT_SUCCESS; 424 } // if 425 426 forceFillCodeLocations( transUnit ); 427 428 PASS( "Fix Init", InitTweak::fix(transUnit, buildingLibrary())); 429 430 // fix ObjectDecl - replaces ConstructorInit nodes 431 if ( ctorinitp ) { 432 dump( move( transUnit ) ); 433 return EXIT_SUCCESS; 434 } // if 435 436 // Currently not working due to unresolved issues with UniqueExpr 437 PASS( "Expand Unique Expr", Tuples::expandUniqueExpr( transUnit ) ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused 438 439 PASS( "Translate Tries", ControlStruct::translateTries( transUnit ) ); 440 PASS( "Gen Waitfor", Concurrency::generateWaitFor( transUnit ) ); 441 442 // Needs to happen before tuple types are expanded. 443 PASS( "Convert Specializations", GenPoly::convertSpecializations( transUnit ) ); 444 445 PASS( "Expand Tuples", Tuples::expandTuples( transUnit ) ); 446 447 if ( tuplep ) { 448 dump( move( transUnit ) ); 449 return EXIT_SUCCESS; 450 } // if 451 452 // Must come after Translate Tries. 453 PASS( "Virtual Expand Casts", Virtual::expandCasts( transUnit ) ); 454 455 translationUnit = convert( move( transUnit ) ); 456 } else { 457 PASS( "Translate Exception Declarations", ControlStruct::translateExcept( translationUnit ) ); 458 if ( exdeclp ) { 459 dump( translationUnit ); 460 return EXIT_SUCCESS; 461 } // if 462 463 // add the assignment statement after the initialization of a type parameter 464 PASS( "Validate", SymTab::validate( translationUnit ) ); 465 466 if ( symtabp ) { 467 deleteAll( translationUnit ); 468 return EXIT_SUCCESS; 469 } // if 470 471 if ( expraltp ) { 472 PassVisitor<ResolvExpr::AlternativePrinter> printer( cout ); 473 acceptAll( translationUnit, printer ); 474 return EXIT_SUCCESS; 475 } // if 476 477 if ( validp ) { 478 dump( translationUnit ); 479 return EXIT_SUCCESS; 480 } // if 481 482 PASS( "Translate Throws", ControlStruct::translateThrows( translationUnit ) ); 483 PASS( "Fix Labels", ControlStruct::fixLabels( translationUnit ) ); 484 PASS( "Fix Names", CodeGen::fixNames( translationUnit ) ); 485 PASS( "Gen Init", InitTweak::genInit( translationUnit ) ); 486 PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( translationUnit ) ); 487 488 if ( libcfap ) { 489 // Generate the bodies of cfa library functions. 490 LibCfa::makeLibCfa( translationUnit ); 491 } // if 492 493 if ( declstatsp ) { 494 CodeTools::printDeclStats( translationUnit ); 495 deleteAll( translationUnit ); 496 return EXIT_SUCCESS; 497 } // if 498 499 if ( bresolvep ) { 500 dump( translationUnit ); 501 return EXIT_SUCCESS; 502 } // if 503 504 CodeTools::fillLocations( translationUnit ); 505 506 if ( resolvprotop ) { 507 CodeTools::dumpAsResolvProto( translationUnit ); 508 return EXIT_SUCCESS; 509 } // if 510 511 PASS( "Resolve", ResolvExpr::resolve( translationUnit ) ); 512 if ( exprp ) { 513 dump( translationUnit ); 514 return EXIT_SUCCESS; 515 } 516 517 PASS( "Fix Init", InitTweak::fix( translationUnit, buildingLibrary() ) ); 518 519 // fix ObjectDecl - replaces ConstructorInit nodes 520 if ( ctorinitp ) { 521 dump ( translationUnit ); 522 return EXIT_SUCCESS; 523 } // if 524 525 PASS( "Expand Unique Expr", Tuples::expandUniqueExpr( translationUnit ) ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused 526 PASS( "Translate Tries", ControlStruct::translateTries( translationUnit ) ); 527 PASS( "Gen Waitfor", Concurrency::generateWaitFor( translationUnit ) ); 528 PASS( "Convert Specializations", GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded 529 PASS( "Expand Tuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this? 530 531 if ( tuplep ) { 532 dump( translationUnit ); 533 return EXIT_SUCCESS; 534 } // if 535 536 PASS( "Virtual Expand Casts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM 323 if (Stats::Counters::enabled) { 324 ast::pass_visitor_stats.avg = Stats::Counters::build<Stats::Counters::AverageCounter<double>>("Average Depth - New"); 325 ast::pass_visitor_stats.max = Stats::Counters::build<Stats::Counters::MaxCounter<double>>("Max depth - New"); 537 326 } 538 539 PASS( "Instantiate Generics", GenPoly::instantiateGeneric( translationUnit ) ); 327 auto transUnit = convert( std::move( translationUnit ) ); 328 329 forceFillCodeLocations( transUnit ); 330 331 PASS( "Translate Exception Declarations", ControlStruct::translateExcept( transUnit ) ); 332 if ( exdeclp ) { 333 dump( std::move( transUnit ) ); 334 return EXIT_SUCCESS; 335 } 336 337 PASS( "Verify Ctor, Dtor & Assign", Validate::verifyCtorDtorAssign( transUnit ) ); 338 PASS( "Hoist Type Decls", Validate::hoistTypeDecls( transUnit ) ); 339 // Hoist Type Decls pulls some declarations out of contexts where 340 // locations are not tracked. Perhaps they should be, but for now 341 // the full fill solves it. 342 forceFillCodeLocations( transUnit ); 343 344 PASS( "Replace Typedefs", Validate::replaceTypedef( transUnit ) ); 345 PASS( "Fix Return Types", Validate::fixReturnTypes( transUnit ) ); 346 PASS( "Enum and Pointer Decay", Validate::decayEnumsAndPointers( transUnit ) ); 347 348 PASS( "Link Reference To Types", Validate::linkReferenceToTypes( transUnit ) ); 349 350 PASS( "Fix Qualified Types", Validate::fixQualifiedTypes( transUnit ) ); 351 PASS( "Hoist Struct", Validate::hoistStruct( transUnit ) ); 352 PASS( "Eliminate Typedef", Validate::eliminateTypedef( transUnit ) ); 353 PASS( "Validate Generic Parameters", Validate::fillGenericParameters( transUnit ) ); 354 PASS( "Translate Dimensions", Validate::translateDimensionParameters( transUnit ) ); 355 PASS( "Check Function Returns", Validate::checkReturnStatements( transUnit ) ); 356 PASS( "Fix Return Statements", InitTweak::fixReturnStatements( transUnit ) ); 357 PASS( "Implement Concurrent Keywords", Concurrency::implementKeywords( transUnit ) ); 358 PASS( "Forall Pointer Decay", Validate::decayForallPointers( transUnit ) ); 359 PASS( "Hoist Control Declarations", ControlStruct::hoistControlDecls( transUnit ) ); 360 361 PASS( "Generate Autogen Routines", Validate::autogenerateRoutines( transUnit ) ); 362 363 PASS( "Implement Mutex", Concurrency::implementMutex( transUnit ) ); 364 PASS( "Implement Thread Start", Concurrency::implementThreadStarter( transUnit ) ); 365 PASS( "Compound Literal", Validate::handleCompoundLiterals( transUnit ) ); 366 PASS( "Set Length From Initializer", Validate::setLengthFromInitializer( transUnit ) ); 367 PASS( "Find Global Decls", Validate::findGlobalDecls( transUnit ) ); 368 PASS( "Fix Label Address", Validate::fixLabelAddresses( transUnit ) ); 369 370 if ( symtabp ) { 371 return EXIT_SUCCESS; 372 } // if 373 374 if ( expraltp ) { 375 ResolvExpr::printCandidates( transUnit ); 376 return EXIT_SUCCESS; 377 } // if 378 379 if ( validp ) { 380 dump( std::move( transUnit ) ); 381 return EXIT_SUCCESS; 382 } // if 383 384 PASS( "Translate Throws", ControlStruct::translateThrows( transUnit ) ); 385 PASS( "Fix Labels", ControlStruct::fixLabels( transUnit ) ); 386 PASS( "Fix Names", CodeGen::fixNames( transUnit ) ); 387 PASS( "Gen Init", InitTweak::genInit( transUnit ) ); 388 PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( transUnit ) ); 389 390 if ( libcfap ) { 391 // Generate the bodies of cfa library functions. 392 LibCfa::makeLibCfa( transUnit ); 393 } // if 394 395 if ( declstatsp ) { 396 printDeclStats( transUnit ); 397 return EXIT_SUCCESS; 398 } // if 399 400 if ( bresolvep ) { 401 dump( std::move( transUnit ) ); 402 return EXIT_SUCCESS; 403 } // if 404 405 if ( resolvprotop ) { 406 dumpAsResolverProto( transUnit ); 407 return EXIT_SUCCESS; 408 } // if 409 410 PASS( "Resolve", ResolvExpr::resolve( transUnit ) ); 411 if ( exprp ) { 412 dump( std::move( transUnit ) ); 413 return EXIT_SUCCESS; 414 } // if 415 416 forceFillCodeLocations( transUnit ); 417 418 PASS( "Fix Init", InitTweak::fix(transUnit, buildingLibrary())); 419 420 // fix ObjectDecl - replaces ConstructorInit nodes 421 if ( ctorinitp ) { 422 dump( std::move( transUnit ) ); 423 return EXIT_SUCCESS; 424 } // if 425 426 // Currently not working due to unresolved issues with UniqueExpr 427 PASS( "Expand Unique Expr", Tuples::expandUniqueExpr( transUnit ) ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused 428 429 PASS( "Translate Tries", ControlStruct::translateTries( transUnit ) ); 430 PASS( "Gen Waitfor", Concurrency::generateWaitFor( transUnit ) ); 431 432 // Needs to happen before tuple types are expanded. 433 PASS( "Convert Specializations", GenPoly::convertSpecializations( transUnit ) ); 434 435 PASS( "Expand Tuples", Tuples::expandTuples( transUnit ) ); 436 437 if ( tuplep ) { 438 dump( std::move( transUnit ) ); 439 return EXIT_SUCCESS; 440 } // if 441 442 // Must come after Translate Tries. 443 PASS( "Virtual Expand Casts", Virtual::expandCasts( transUnit ) ); 444 445 PASS( "Instantiate Generics", GenPoly::instantiateGeneric( transUnit ) ); 446 447 translationUnit = convert( std::move( transUnit ) ); 448 540 449 if ( genericsp ) { 541 450 dump( translationUnit ); … … 620 529 621 530 622 static const char optstring[] = ":c:ghlLmNnpd OAP:S:twW:D:";531 static const char optstring[] = ":c:ghlLmNnpdP:S:twW:D:"; 623 532 624 533 enum { PreludeDir = 128 }; … … 634 543 { "prototypes", no_argument, nullptr, 'p' }, 635 544 { "deterministic-out", no_argument, nullptr, 'd' }, 636 { "old-ast", no_argument, nullptr, 'O'},637 { "new-ast", no_argument, nullptr, 'A'},638 545 { "print", required_argument, nullptr, 'P' }, 639 546 { "prelude-dir", required_argument, nullptr, PreludeDir }, … … 657 564 "do not generate prelude prototypes => prelude not printed", // -p 658 565 "only print deterministic output", // -d 659 "Use the old-ast", // -O660 "Use the new-ast", // -A661 566 "print", // -P 662 567 "<directory> prelude directory for debug/nodebug", // no flag … … 767 672 deterministic_output = true; 768 673 break; 769 case 'O': // don't print non-deterministic output770 useNewAST = false;771 break;772 case 'A': // don't print non-deterministic output773 useNewAST = true;774 break;775 674 case 'P': // print options 776 675 for ( int i = 0;; i += 1 ) { … … 889 788 890 789 static void dump( ast::TranslationUnit && transUnit, ostream & out ) { 891 std::list< Declaration * > translationUnit = convert( move( transUnit ) );790 std::list< Declaration * > translationUnit = convert( std::move( transUnit ) ); 892 791 dump( translationUnit, out ); 893 792 }
Note:
See TracChangeset
for help on using the changeset viewer.