Changeset 23a08aa0 for src


Ignore:
Timestamp:
Sep 19, 2022, 8:11:02 PM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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.
Message:

fix merge conflict

Location:
src
Files:
1 added
42 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.hpp

    rebf8ca5 r23a08aa0  
    217217
    218218        /// convenience accessor to match Type::isComplete()
    219         bool isComplete() { return sized; }
     219        bool isComplete() const { return sized; }
    220220
    221221        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
  • src/AST/DeclReplacer.cpp

    rebf8ca5 r23a08aa0  
    99// Author           : Aaron B. Moss
    1010// Created On       : Wed May 8 13:00:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Wed May 8 13:00:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Sep 15 11:55:00 2022
     13// Update Count     : 2
    1414//
    1515
    1616#include "DeclReplacer.hpp"
     17
    1718#include "Expr.hpp"
     19#include "Pass.hpp"
    1820#include "Type.hpp"
    19 
    20 #include "Pass.hpp"
    2121
    2222namespace ast {
    2323
    2424namespace DeclReplacer {
    25         namespace {
    26                 struct DeclReplacer {
    27                 private:
    28                         const DeclMap & declMap;
    29                         const TypeMap & typeMap;
    30                         bool debug;
    3125
    32                 public:
    33                         DeclReplacer(const DeclMap & declMap, const TypeMap & typeMap, bool debug)
    34                                 : declMap( declMap ), typeMap( typeMap ), debug( debug )
    35                         {}
     26namespace {
     27        struct DeclReplacer {
     28        private:
     29                const DeclMap & declMap;
     30                const TypeMap & typeMap;
     31                bool debug;
    3632
    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                {}
    4037
    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        };
    4741
    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
     53const 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
     59const ast::Node * replace( const ast::Node * node, const DeclMap & declMap, bool debug ) {
     60        TypeMap typeMap;
     61        return replace( node, declMap, typeMap, debug );
     62}
     63
     64const ast::Node * replace( const ast::Node * node, const TypeMap & typeMap, bool debug ) {
     65        DeclMap declMap;
     66        return replace( node, declMap, typeMap, debug );
     67}
     68
     69const ast::Node * replace( const ast::Node * node, const ExprMap & exprMap ) {
     70        Pass<VarExprReplacer> replacer = {exprMap};
     71        return node->accept( replacer );
     72}
     73
     74namespace {
     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;
    5090        }
    5191
    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;
    56105        }
    57106
    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 );
    61110        }
     111} // namespace
    62112
    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
    67114
    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
    116116
    117117// Local Variables: //
  • src/AST/Pass.hpp

    rebf8ca5 r23a08aa0  
    327327struct PureVisitor {};
    328328
     329struct WithCodeLocation {
     330        const CodeLocation * location = nullptr;
     331};
     332
    329333/// Keep track of the polymorphic const TypeSubstitution * typeSubs for the current expression.
    330334struct WithConstTypeSubstitution {
  • src/AST/Pass.impl.hpp

    rebf8ca5 r23a08aa0  
    2525#define VISIT_START( node ) \
    2626        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 ); \
    2729        /* back-up the visit children */ \
    2830        __attribute__((unused)) ast::__pass::visit_children_guard guard1( ast::__pass::visit_children(core, 0) ); \
  • src/AST/Pass.proto.hpp

    rebf8ca5 r23a08aa0  
    326326        }
    327327
     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
    328341        // Another feature of the templated visitor is that it calls beginScope()/endScope() for compound statement.
    329342        // All passes which have such functions are assumed desire this behaviour
  • src/AST/Print.cpp

    rebf8ca5 r23a08aa0  
    3333{
    3434        return array<C,sizeof...(T)>{
    35                 forward<T>(values)...
     35                std::forward<T>(values)...
    3636        };
    3737}
     
    8686
    8787                static constexpr auto StorageClasses = make_array<const char*>(
    88                         "extern", "static", "auto", "register", "_Thread_local"
     88                        "extern", "static", "auto", "register", "__thread", "_Thread_local"
    8989                );
    9090
     
    215215                        ++indent;
    216216                        ptrToEnum->base->accept( *this );
    217                         --indent; 
     217                        --indent;
    218218                }
    219219
     
    16231623// if the wrong size is specified
    16241624constexpr array<const char*, 3> Printer::Names::FuncSpecifiers;
    1625 constexpr array<const char*, 5> Printer::Names::StorageClasses;
     1625constexpr array<const char*, 6> Printer::Names::StorageClasses;
    16261626constexpr array<const char*, 6> Printer::Names::Qualifiers;
    16271627}
  • src/AST/StorageClasses.hpp

    rebf8ca5 r23a08aa0  
    2424        /// Bitflags for storage classes
    2525        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
    3233        };
    3334
     
    3738                        unsigned int val;
    3839                        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;
    4446                        };
    4547
     
    4850
    4951                constexpr class_flags( unsigned int val = 0 ) : val(val) {}
     52
     53                bool is_threadlocal_any() { return this->is_threadlocalC11 || this->is_threadlocalGcc; }
    5054        };
    5155
  • src/AST/Type.cpp

    rebf8ca5 r23a08aa0  
    143143TraitInstType::TraitInstType(
    144144        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 ) {}
    146146
    147147// --- TypeInstType
     
    149149TypeInstType::TypeInstType( const TypeDecl * b,
    150150        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 ) {}
    152152
    153153void TypeInstType::set_base( const TypeDecl * b ) {
     
    161161
    162162TupleType::TupleType( std::vector<ptr<Type>> && ts, CV::Qualifiers q )
    163 : Type( q ), types( move(ts) ), members() {
     163: Type( q ), types( std::move(ts) ), members() {
    164164        // This constructor is awkward. `TupleType` needs to contain objects so that members can be
    165165        // named, but members without initializer nodes end up getting constructors, which breaks
  • src/AST/Type.hpp

    rebf8ca5 r23a08aa0  
    8383template< enum Node::ref_type ref_t >
    8484void 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;
    8686}
    8787
     
    8989template< enum Node::ref_type ref_t >
    9090void 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;
    9292}
    9393
     
    9595template< enum Node::ref_type ref_t >
    9696void 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;
    9898}
    9999
     
    412412                std::string typeString() const { return std::string("_") + std::to_string(formal_usage) + "_" + std::to_string(expr_id) + "_" + base->name; }
    413413                bool operator==(const TypeEnvKey & other) const { return base == other.base && formal_usage == other.formal_usage && expr_id == other.expr_id; }
    414 
    415414        };
    416415
  • src/CodeGen/CodeGenerator.cc

    rebf8ca5 r23a08aa0  
    493493                                        assert( false );
    494494                                } // 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 << ")";
    495501                        } else {
    496502                                varExpr->accept( *visitor );
  • src/Common/utility.h

    rebf8ca5 r23a08aa0  
    322322
    323323        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; }
    324326        ~ValueGuardPtr() { if( ref ) *ref = old; }
    325327};
  • src/CompilationState.cc

    rebf8ca5 r23a08aa0  
    3131        genproto = false,
    3232        deterministic_output = false,
    33         useNewAST = CFA_USE_NEW_AST,
     33        useNewAST = true,
    3434        nomainp = false,
    3535        parsep = false,
  • src/Concurrency/Keywords.cc

    rebf8ca5 r23a08aa0  
    508508                ObjectDecl * vtable_object = Virtual::makeVtableForward(
    509509                        "_default_vtable_object_declaration",
    510                         vtable_decl->makeInst( move( poly_args ) ) );
     510                        vtable_decl->makeInst( std::move( poly_args ) ) );
    511511                declsToAddBefore.push_back( vtable_object );
    512512                declsToAddBefore.push_back(
     
    681681                        void lock (monitor_t & this) {
    682682                                lock(get_monitor(this));
    683                         }       
     683                        }
    684684                */
    685685                FunctionDecl * lock_decl = new FunctionDecl(
     
    700700                CompoundStmt * lock_statement = new CompoundStmt();
    701701                lock_statement->push_back(
    702                         new ExprStmt( 
     702                        new ExprStmt(
    703703                                new UntypedExpr (
    704704                                        new NameExpr( "lock" ),
     
    716716                        void unlock (monitor_t & this) {
    717717                                unlock(get_monitor(this));
    718                         }       
     718                        }
    719719                */
    720720                FunctionDecl * unlock_decl = new FunctionDecl(
     
    736736
    737737                unlock_statement->push_back(
    738                         new ExprStmt( 
     738                        new ExprStmt(
    739739                                new UntypedExpr(
    740740                                        new NameExpr( "unlock" ),
     
    746746                );
    747747                unlock_decl->set_statements( unlock_statement );
    748                
     748
    749749                // pushes routines to declsToAddAfter to add at a later time
    750750                declsToAddAfter.push_back( lock_decl );
     
    10541054                        assert( !thread_guard_decl );
    10551055                        thread_guard_decl = decl;
    1056                 } 
     1056                }
    10571057                else if ( decl->name == "__mutex_stmt_lock_guard" && decl->body ) {
    10581058                        assert( !lock_guard_decl );
     
    12061206                                                        new NameExpr( "__get_mutexstmt_lock_type" ),
    12071207                                                        { args.front()->clone() }
    1208                                                 ) 
     1208                                                )
    12091209                                        )
    12101210                                ),
     
    12251225
    12261226                StructInstType * lock_guard_struct = new StructInstType( noQualifiers, lock_guard_decl );
    1227                 TypeExpr * lock_type_expr = new TypeExpr( 
     1227                TypeExpr * lock_type_expr = new TypeExpr(
    12281228                        new TypeofType( noQualifiers, new UntypedExpr(
    12291229                                new NameExpr( "__get_mutexstmt_lock_type" ),
    12301230                                { args.front()->clone() }
    1231                                 ) 
    1232                         ) 
     1231                                )
     1232                        )
    12331233                );
    12341234
  • src/Concurrency/Waitfor.cc

    rebf8ca5 r23a08aa0  
    402402
    403403                clause.target.function = nullptr;
    404                 clause.target.arguments.empty();
     404                clause.target.arguments.clear();
    405405                clause.condition = nullptr;
    406406        }
  • src/Concurrency/WaitforNew.cpp

    rebf8ca5 r23a08aa0  
    101101namespace {
    102102
    103 class GenerateWaitForCore :
     103class GenerateWaitForCore final :
    104104                public ast::WithSymbolTable, public ast::WithConstTranslationUnit {
    105105        const ast::FunctionDecl * decl_waitfor    = nullptr;
  • src/ControlStruct/ExceptTranslateNew.cpp

    rebf8ca5 r23a08aa0  
    3232        }
    3333
    34 class TranslateThrowsCore : public ast::WithGuards {
     34class TranslateThrowsCore final : public ast::WithGuards {
    3535        const ast::ObjectDecl * terminateHandlerExcept;
    3636        enum Context { NoHandler, TerHandler, ResHandler } currentContext;
     
    136136
    137137
    138 class TryMutatorCore {
     138class TryMutatorCore final {
    139139        // The built in types used in translation.
    140140        const ast::StructDecl * except_decl;
  • src/ControlStruct/LabelFixer.cc

    rebf8ca5 r23a08aa0  
    119119
    120120// Builds a table that maps a label to its defining statement.
    121 std::map<Label, Statement * > * LabelFixer::resolveJumps() throw ( SemanticErrorException ) {
     121std::map<Label, Statement * > * LabelFixer::resolveJumps() {
    122122        std::map< Label, Statement * > *ret = new std::map< Label, Statement * >();
    123123        for ( std::map< Label, Entry * >::iterator i = labelTable.begin(); i != labelTable.end(); ++i ) {
  • src/ControlStruct/LabelFixer.h

    rebf8ca5 r23a08aa0  
    3333        LabelFixer( LabelGenerator *gen = 0 );
    3434
    35         std::map < Label, Statement * > *resolveJumps() throw ( SemanticErrorException );
     35        std::map < Label, Statement * > *resolveJumps();
    3636
    3737        // Declarations
  • src/ControlStruct/MLEMutator.cc

    rebf8ca5 r23a08aa0  
    141141
    142142
    143         Statement *MultiLevelExitMutator::postmutate( BranchStmt *branchStmt )
    144                         throw ( SemanticErrorException ) {
     143        Statement *MultiLevelExitMutator::postmutate( BranchStmt *branchStmt ) {
    145144                std::string originalTarget = branchStmt->originalTarget;
    146145
  • src/ControlStruct/MLEMutator.h

    rebf8ca5 r23a08aa0  
    4141
    4242                void premutate( CompoundStmt *cmpndStmt );
    43                 Statement * postmutate( BranchStmt *branchStmt ) throw ( SemanticErrorException );
     43                Statement * postmutate( BranchStmt *branchStmt );
    4444                void premutate( WhileDoStmt *whileDoStmt );
    4545                Statement * postmutate( WhileDoStmt *whileDoStmt );
  • src/GenPoly/GenPoly.cc

    rebf8ca5 r23a08aa0  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun 29 21:45:53 2016
    13 // Update Count     : 14
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Sep 14  9:24:00 2022
     13// Update Count     : 15
    1414//
    1515
     
    8383                }
    8484
     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
    8596                /// Checks a parameter list for inclusion of polymorphic parameters; will substitute according to env if present
    8697                bool includesPolyParams( std::list< Expression* >& params, const TypeSubstitution *env ) {
     
    198209                }
    199210                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;
    200231        }
    201232
     
    378409                inline D* as( B* p ) { return reinterpret_cast<D*>(p); }
    379410
     411                template<typename D, typename B>
     412                inline D const * as( B const * p ) {
     413                        return reinterpret_cast<D const *>( p );
     414                }
     415
    380416                /// Flattens a declaration list
    381417                template<typename Output>
     
    391427                        for ( Type* ty : src ) {
    392428                                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 );
    393436                        }
    394437                }
     
    409452                                // if ( is<VoidType>( aparam->get_type() ) || is<VoidType>( bparam->get_type() ) ) continue;
    410453                                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                                }
    411479                        }
    412480
     
    505573        }
    506574
     575bool 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
    507687        namespace {
    508688                // temporary hack to avoid re-implementing anything related to TyVarMap
  • src/GenPoly/GenPoly.h

    rebf8ca5 r23a08aa0  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:22:57 2017
    13 // Update Count     : 7
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Aug 19 16:03:00 2022
     13// Update Count     : 8
    1414//
    1515
     
    2727namespace GenPoly {
    2828
     29        // TODO Via some tricks this works for ast::TypeDecl::Data as well.
    2930        typedef ErasableScopedMap< std::string, TypeDecl::Data > TyVarMap;
     31
    3032        /// Replaces a TypeInstType by its referrent in the environment, if applicable
    3133        Type* replaceTypeInst( Type* type, const TypeSubstitution* env );
     
    4143        /// returns dynamic-layout type if is dynamic-layout type in tyVars, NULL otherwise; will look up substitution in env if provided
    4244        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 );
    4346
    4447        /// true iff function has dynamic-layout return type under the given type variable map
     
    8386        /// true iff types are structurally identical, where TypeInstType's match any type.
    8487        bool typesPolyCompatible( Type *aty, Type *bty );
     88        bool typesPolyCompatible( ast::Type const * lhs, ast::Type const * rhs );
    8589
    8690        /// true if arg requires boxing given exprTyVars
  • src/GenPoly/InstantiateGeneric.h

    rebf8ca5 r23a08aa0  
    1919
    2020class Declaration;
     21namespace ast {
     22        class TranslationUnit;
     23}
    2124
    2225namespace 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.
     30void instantiateGeneric( std::list< Declaration* > &translationUnit );
     31void instantiateGeneric( ast::TranslationUnit & translationUnit );
    2732} // namespace GenPoly
    2833
  • src/GenPoly/Lvalue2.cc

    rebf8ca5 r23a08aa0  
    2323}
    2424
    25 
    2625}
  • src/GenPoly/ScrubTyVars.cc

    rebf8ca5 r23a08aa0  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 15:44:27 2017
    13 // Update Count     : 3
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Aug 19 16:10:00 2022
     13// Update Count     : 4
    1414//
    1515
    1616#include <utility>                      // for pair
    1717
     18#include "AST/Pass.hpp"
    1819#include "GenPoly.h"                    // for mangleType, TyVarMap, alignof...
    1920#include "GenPoly/ErasableScopedMap.h"  // for ErasableScopedMap<>::const_it...
    2021#include "ScrubTyVars.h"
     22#include "SymTab/Mangler.h"             // for mangle, typeMode
    2123#include "SynTree/Declaration.h"        // for TypeDecl, TypeDecl::Data, Typ...
    2224#include "SynTree/Expression.h"         // for Expression (ptr only), NameExpr
     
    112114                return pointer;
    113115        }
     116
     117namespace {
     118
     119enum class ScrubMode {
     120        FromMap,
     121        DynamicFromMap,
     122        All,
     123};
     124
     125struct 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
     147private:
     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
     185ast::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
     217ast::Type const * ScrubTypeVars::postvisit( ast::StructInstType const * type ) {
     218        return postvisitAggregateType( type );
     219}
     220
     221ast::Type const * ScrubTypeVars::postvisit( ast::UnionInstType const * type ) {
     222        return postvisitAggregateType( type );
     223}
     224
     225ast::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
     235ast::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
     245ast::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
     255const 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
     269template<>
     270ast::Node const * scrubAllTypeVars<ast::Node>( const ast::Node * target ) {
     271        return scrubTypeVarsBase( target, ScrubMode::All, nullptr );
     272}
     273
    114274} // namespace GenPoly
    115275
  • src/GenPoly/ScrubTyVars.h

    rebf8ca5 r23a08aa0  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:21:47 2017
    13 // Update Count     : 2
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Aug 19 14:14:00 2022
     13// Update Count     : 3
    1414//
    1515
     
    1818#include <cassert>            // for assert
    1919
     20#include "AST/Fwd.hpp"        // for Node
    2021#include "Common/PassVisitor.h"
    2122#include "GenPoly.h"          // for TyVarMap, isPolyType, isDynType
     
    108109        }
    109110
     111/// For all polymorphic types, replaces generic types, with the appropriate
     112/// void type, and sizeof/alignof expressions with the proper variable.
     113template<typename node_t>
     114node_t const * scrubAllTypeVars( node_t const * target ) {
     115        return strict_dynamic_cast<node_t const *>( scrubAllTypeVars<ast::Node>( target ) );
     116}
     117
     118template<>
     119ast::Node const * scrubAllTypeVars<ast::Node>( const ast::Node * target );
     120
    110121} // namespace GenPoly
    111122
  • src/GenPoly/SpecializeNew.cpp

    rebf8ca5 r23a08aa0  
    240240}
    241241
    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 }
     242struct 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};
    259257
    260258const ast::Expr * SpecializeCore::createThunkFunction(
  • src/GenPoly/module.mk

    rebf8ca5 r23a08aa0  
    2727        GenPoly/FindFunction.cc \
    2828        GenPoly/FindFunction.h \
     29        GenPoly/InstantiateGenericNew.cpp \
    2930        GenPoly/InstantiateGeneric.cc \
    3031        GenPoly/InstantiateGeneric.h \
  • src/InitTweak/InitTweak.cc

    rebf8ca5 r23a08aa0  
    12411241        static const char * const tlsd_section = ".tdata" ASM_COMMENT;
    12421242        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();
    12441244                const char * section = is_tls ? tlsd_section : data_section;
    12451245                objDecl->attributes.push_back(new Attribute("section", {
     
    12491249
    12501250        void addDataSectionAttribute( ast::ObjectDecl * objDecl ) {
    1251                 const bool is_tls = objDecl->storage.is_threadlocal;
     1251                const bool is_tls = objDecl->storage.is_threadlocal_any();
    12521252                const char * section = is_tls ? tlsd_section : data_section;
    12531253                objDecl->attributes.push_back(new ast::Attribute("section", {
  • src/Makefile.am

    rebf8ca5 r23a08aa0  
    7171EXTRA_DIST = include/cassert include/optional BasicTypes-gen.cc
    7272
    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++14 $(TCMALLOCFLAG)
     73AM_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)
    7474AM_LDFLAGS  = @HOST_FLAGS@ -Xlinker -export-dynamic
    7575ARFLAGS     = cr
  • src/Parser/DeclarationNode.cc

    rebf8ca5 r23a08aa0  
    262262        newnode->type->enumeration.anon = name == nullptr;
    263263        if ( base && base->type)  {
    264                 newnode->type->base = base->type;       
     264                newnode->type->base = base->type;
    265265        } // if
    266266
     
    505505                        } // for
    506506                        // 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 ?
    508508                        appendError( error, string( "conflicting " ) + Type::StorageClassesNames[storageClasses.ffs()] +
    509509                                                 " & " + Type::StorageClassesNames[src->storageClasses.ffs()] );
  • src/Parser/lex.ll

    rebf8ca5 r23a08aa0  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Sun Jun 20 18:41:09 2021
    13  * Update Count     : 759
     12 * Last Modified On : Tue Aug 30 18:39:54 2022
     13 * Update Count     : 760
    1414 */
    1515
     
    314314switch                  { KEYWORD_RETURN(SWITCH); }
    315315thread                  { KEYWORD_RETURN(THREAD); }                             // C11
    316 _Thread_local   { KEYWORD_RETURN(THREADLOCAL); }                // C11
     316__thread                { KEYWORD_RETURN(THREADLOCALGCC); }             // GCC
     317_Thread_local   { KEYWORD_RETURN(THREADLOCALC11); }             // C11
    317318throw                   { KEYWORD_RETURN(THROW); }                              // CFA
    318319throwResume             { KEYWORD_RETURN(THROWRESUME); }                // CFA
  • src/Parser/parser.yy

    rebf8ca5 r23a08aa0  
    5858
    5959// 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"
    6163
    6264extern DeclarationNode * parseTree;
     
    293295%token TYPEDEF
    294296%token EXTERN STATIC AUTO REGISTER
    295 %token THREADLOCAL                                                                              // C11
     297%token THREADLOCALGCC THREADLOCALC11                                            // GCC, C11
    296298%token INLINE FORTRAN                                                                   // C99, extension ISO/IEC 9899:1999 Section J.5.9(1)
    297299%token NORETURN                                                                                 // C11
     
    13451347                {
    13461348                        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; }
    13481350                }
    13491351        | comma_expression updowneq comma_expression '~' comma_expression // CFA, anonymous loop-index
     
    13571359                {
    13581360                        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; }
    13601362                }
    13611363        | comma_expression updowneq comma_expression '~' '@' // CFA, error
     
    20822084        | REGISTER
    20832085                { $$ = 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 ); }
    20862090                // Put function specifiers here to simplify parsing rules, but separate them semantically.
    20872091        | INLINE                                                                                        // C99
  • src/ResolvExpr/CandidateFinder.cpp

    rebf8ca5 r23a08aa0  
    269269                        unsigned nextArg, unsigned tupleStart = 0, Cost cost = Cost::zero,
    270270                        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 ),
    273273                  nextExpl( nextExpl ), explAlt( explAlt ) {}
    274274
     
    276276                        const ArgPack & o, ast::TypeEnvironment && env, ast::AssertionSet && need,
    277277                        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 ),
    280280                  tupleStart( o.tupleStart ), nextExpl( 0 ), explAlt( 0 ) {}
    281281
     
    301301                        // reset pack to appropriate tuple
    302302                        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 ) };
    304304                        tupleStart = pack->tupleStart - 1;
    305305                        parent = pack->parent;
     
    404404                                                                newResult.open, symtab )
    405405                                                ) {
    406                                                         finalResults.emplace_back( move( newResult ) );
     406                                                        finalResults.emplace_back( std::move( newResult ) );
    407407                                                }
    408408
     
    423423                                                if ( expl.exprs.empty() ) {
    424424                                                        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 );
    427427
    428428                                                        continue;
     
    431431                                                // add new result
    432432                                                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,
    435435                                                        expl.cost, expl.exprs.size() == 1 ? 0 : 1, j );
    436436                                        }
     
    444444                        // splice final results onto results
    445445                        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] ) );
    447447                        }
    448448                        return ! finalResults.empty();
     
    478478
    479479                                        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,
    481481                                                nTuples, Cost::zero, nextExpl, results[i].explAlt );
    482482                                }
     
    494494                                        if ( unify( paramType, cnst->result, env, need, have, open, symtab ) ) {
    495495                                                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 );
    498498                                        }
    499499                                }
     
    516516                                if ( expl.exprs.empty() ) {
    517517                                        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 ),
    519519                                                nextArg + 1, expl.cost );
    520520
     
    538538                                        // add new result
    539539                                        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 ),
    541541                                                nextArg + 1, nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j );
    542542                                }
     
    576576                                        restructureCast( idx, toType->getComponent( i ), isGenerated ) );
    577577                        }
    578                         return new ast::TupleExpr{ arg->location, move( components ) };
     578                        return new ast::TupleExpr{ arg->location, std::move( components ) };
    579579                } else {
    580580                        // handle normally
     
    672672                        }
    673673                        std::vector< ast::ptr< ast::Expr > > vargs( args.begin(), args.end() );
    674                         appExpr->args = move( vargs );
     674                        appExpr->args = std::move( vargs );
    675675                        // build and validate new candidate
    676676                        auto newCand =
     
    783783                                                        if ( expl.exprs.empty() ) {
    784784                                                                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,
    787787                                                                        expl.cost );
    788788
     
    792792                                                        // add new result
    793793                                                        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,
    796796                                                                expl.exprs.size() == 1 ? 0 : 1, j );
    797797                                                }
     
    843843                                // as a member expression
    844844                                addAnonConversions( newCand );
    845                                 candidates.emplace_back( move( newCand ) );
     845                                candidates.emplace_back( std::move( newCand ) );
    846846                        }
    847847                }
     
    901901                                                        const ast::EnumDecl * enumDecl = enumInst->base;
    902902                                                        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)
    904904                                                                funcFinder.otypeKeys.insert(Mangle::mangle(enumType, Mangle::NoGenericParams | Mangle::Type));
    905905                                                        } else {
     
    907907                                                                funcFinder.otypeKeys.insert(Mangle::mangle(enumDecl, Mangle::NoGenericParams | Mangle::Type));
    908908                                                        }
    909                                                 } 
     909                                                }
    910910                                                else funcFinder.otypeKeys.insert(Mangle::mangle(argType, Mangle::NoGenericParams | Mangle::Type));
    911911                                        }
     
    986986                                        funcE.emplace_back( *func, symtab );
    987987                                }
    988                                 argExpansions.emplace_front( move( funcE ) );
     988                                argExpansions.emplace_front( std::move( funcE ) );
    989989
    990990                                for ( const CandidateRef & op : opFinder ) {
     
    10301030                                if ( cvtCost != Cost::infinity ) {
    10311031                                        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 );
    10361036
    10371037                        // use a new list so that candidates are not examined by addAnonConversions twice
     
    11311131                                        CandidateRef newCand = std::make_shared<Candidate>(
    11321132                                                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,
    11341134                                                cand->cost + thisCost );
    11351135                                        inferParameters( newCand, matches );
     
    12851285                                // as a name expression
    12861286                                addAnonConversions( newCand );
    1287                                 candidates.emplace_back( move( newCand ) );
     1287                                candidates.emplace_back( std::move( newCand ) );
    12881288                        }
    12891289                }
     
    13941394                                                new ast::LogicalExpr{
    13951395                                                        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 );
    13971397                                }
    13981398                        }
     
    14521452                                                        // output candidate
    14531453                                                        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 );
    14551455                                                        inferParameters( newCand, candidates );
    14561456                                                }
     
    15191519                                                // add candidate
    15201520                                                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 ),
    15221522                                                        r1->cost + r2->cost );
    15231523                                                inferParameters( newCand, candidates );
     
    15481548
    15491549                                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 ) );
    15521552                        }
    15531553                }
     
    16351635                                                                initExpr->location, restructureCast( cand->expr, toType ),
    16361636                                                                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 );
    16381638                                                inferParameters( newCand, matches );
    16391639                                        }
     
    17681768                cand->env.applyFree( newResult );
    17691769                cand->expr = ast::mutate_field(
    1770                         cand->expr.get(), &ast::Expr::result, move( newResult ) );
     1770                        cand->expr.get(), &ast::Expr::result, std::move( newResult ) );
    17711771
    17721772                out.emplace_back( cand );
     
    18541854
    18551855                auto oldsize = candidates.size();
    1856                 candidates = move( pruned );
     1856                candidates = std::move( pruned );
    18571857
    18581858                PRINT(
  • src/SynTree/Statement.cc

    rebf8ca5 r23a08aa0  
    105105};
    106106
    107 BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticErrorException ) :
     107BranchStmt::BranchStmt( Label target, Type type ) :
    108108        Statement(), originalTarget( target ), target( target ), computedTarget( nullptr ), type( type ) {
    109109        //actually this is a syntactic error signaled by the parser
     
    113113}
    114114
    115 BranchStmt::BranchStmt( Expression * computedTarget, Type type ) throw ( SemanticErrorException ) :
     115BranchStmt::BranchStmt( Expression * computedTarget, Type type ) :
    116116        Statement(), computedTarget( computedTarget ), type( type ) {
    117117        if ( type != BranchStmt::Goto || computedTarget == nullptr ) {
     
    211211}
    212212
    213 CaseStmt::CaseStmt( Expression * condition, const list<Statement *> & statements, bool deflt ) throw ( SemanticErrorException ) :
     213CaseStmt::CaseStmt( Expression * condition, const list<Statement *> & statements, bool deflt ) :
    214214                Statement(), condition( condition ), stmts( statements ), _isDefault( deflt ) {
    215215        if ( isDefault() && condition != nullptr ) SemanticError( condition, "default case with condition: " );
     
    575575}
    576576
    577 MutexStmt::MutexStmt( Statement * stmt, const list<Expression *> mutexObjs ) 
     577MutexStmt::MutexStmt( Statement * stmt, const list<Expression *> mutexObjs )
    578578        : Statement(), stmt( stmt ), mutexObjs( mutexObjs ) { }
    579579
  • src/SynTree/Statement.h

    rebf8ca5 r23a08aa0  
    200200        std::list<Statement *> stmts;
    201201
    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 );
    203203        CaseStmt( const CaseStmt & other );
    204204        virtual ~CaseStmt();
     
    289289        Type type;
    290290
    291         BranchStmt( Label target, Type ) throw (SemanticErrorException);
    292         BranchStmt( Expression * computedTarget, Type ) throw (SemanticErrorException);
     291        BranchStmt( Label target, Type );
     292        BranchStmt( Expression * computedTarget, Type );
    293293
    294294        Label get_originalTarget() { return originalTarget; }
  • src/SynTree/Type.cc

    rebf8ca5 r23a08aa0  
    8080// These must remain in the same order as the corresponding bit fields.
    8181const char * Type::FuncSpecifiersNames[] = { "inline", "_Noreturn", "fortran" };
    82 const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "_Thread_local" };
     82const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "__thread", "_Thread_local" };
    8383const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "mutex", "_Atomic" };
    8484
  • src/SynTree/Type.h

    rebf8ca5 r23a08aa0  
    8484        }; // FuncSpecifiers
    8585
    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 };
    8787        static const char * StorageClassesNames[];
    8888        union StorageClasses {
     
    9393                        bool is_auto : 1;
    9494                        bool is_register : 1;
    95                         bool is_threadlocal : 1;
     95                        bool is_threadlocalGcc : 1;
     96                        bool is_threadlocalC11 : 1;
    9697                };
    9798
     
    100101                // equality (==, !=) works implicitly on first field "val", relational operations are undefined.
    101102                BFCommon( StorageClasses, NumStorageClass )
     103
     104                bool is_threadlocal_any() { return this->is_threadlocalC11 || this->is_threadlocalGcc; }
    102105        }; // StorageClasses
    103106
  • src/Tuples/TupleExpansionNew.cpp

    rebf8ca5 r23a08aa0  
    101101
    102102/// Replaces Tuple Assign & Index Expressions, and Tuple Types.
    103 struct TupleMainExpander :
     103struct TupleMainExpander final :
    104104                public ast::WithGuards,
    105105                public ast::WithVisitorRef<TupleMainExpander>,
     
    254254}
    255255
    256 struct TupleExprExpander {
     256struct TupleExprExpander final {
    257257        ast::Expr const * postvisit( ast::TupleExpr const * expr ) {
    258258                return replaceTupleExpr( expr->location,
  • src/Virtual/ExpandCasts.cc

    rebf8ca5 r23a08aa0  
    317317};
    318318
    319 struct ExpandCastsCore {
     319struct ExpandCastsCore final {
    320320        void previsit( ast::FunctionDecl const * decl );
    321321        void previsit( ast::StructDecl const * decl );
     
    362362}
    363363
     364/// Copy newType, but give the copy the params of the oldType.
    364365ast::StructInstType * polyCopy(
    365366                ast::StructInstType const * oldType,
  • src/config.h.in

    rebf8ca5 r23a08aa0  
    2727/* Location of cfa install. */
    2828#undef CFA_PREFIX
    29 
    30 /* Sets whether or not to use the new-ast, this is adefault value and can be
    31    overrided by --old-ast and --new-ast */
    32 #undef CFA_USE_NEW_AST
    3329
    3430/* Major.Minor */
  • src/main.cc

    rebf8ca5 r23a08aa0  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thu 11 12:18:00 2022
    13 // Update Count     : 677
     12// Last Modified On : Thu Sep 15 13:58:00 2022
     13// Update Count     : 678
    1414//
    1515
     
    3838#include "CodeGen/Generate.h"               // for generate
    3939#include "CodeGen/LinkOnce.h"               // for translateLinkOnce
    40 #include "CodeTools/DeclStats.h"            // for printDeclStats
    41 #include "CodeTools/ResolvProtoDump.h"      // for dumpAsResolvProto
    4240#include "CodeTools/TrackLoc.h"             // for fillLocations
    4341#include "Common/CodeLocationTools.hpp"     // for forceFillCodeLocations
     
    4543#include "Common/DeclStats.hpp"             // for printDeclStats
    4644#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
    5046#include "Common/UnimplementedError.h"      // for UnimplementedError
    5147#include "Common/utility.h"                 // for deleteAll, filter, printAll
     
    5349#include "Concurrency/Waitfor.h"            // for generateWaitfor
    5450#include "ControlStruct/ExceptDecl.h"       // for translateExcept
    55 #include "ControlStruct/ExceptTranslate.h"  // for translateEHM
     51#include "ControlStruct/ExceptTranslate.h"  // for translateThrows, translat...
    5652#include "ControlStruct/FixLabels.hpp"      // for fixLabels
    5753#include "ControlStruct/HoistControlDecls.hpp" //  hoistControlDecls
    58 #include "ControlStruct/Mutate.h"           // for mutate
    5954#include "GenPoly/Box.h"                    // for box
    6055#include "GenPoly/InstantiateGeneric.h"     // for instantiateGeneric
     
    6661#include "Parser/ParseNode.h"               // for DeclarationNode, buildList
    6762#include "Parser/TypedefTable.h"            // for TypedefTable
    68 #include "ResolvExpr/AlternativePrinter.h"  // for AlternativePrinter
    6963#include "ResolvExpr/CandidatePrinter.hpp"  // for printCandidates
    7064#include "ResolvExpr/Resolver.h"            // for resolve
    71 #include "SymTab/Validate.h"                // for validate
    72 #include "SymTab/ValidateType.h"            // for linkReferenceToTypes
    7365#include "SynTree/LinkageSpec.h"            // for Spec, Cforall, Intrinsic
    7466#include "SynTree/Declaration.h"            // for Declaration
    75 #include "SynTree/Visitor.h"                // for acceptAll
    7667#include "Tuples/Tuples.h"                  // for expandMemberTuples, expan...
    7768#include "Validate/Autogen.hpp"             // for autogenerateRoutines
     
    330321                Stats::Time::StopBlock();
    331322
    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");
    537326                }
    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
    540449                if ( genericsp ) {
    541450                        dump( translationUnit );
     
    620529
    621530
    622 static const char optstring[] = ":c:ghlLmNnpdOAP:S:twW:D:";
     531static const char optstring[] = ":c:ghlLmNnpdP:S:twW:D:";
    623532
    624533enum { PreludeDir = 128 };
     
    634543        { "prototypes", no_argument, nullptr, 'p' },
    635544        { "deterministic-out", no_argument, nullptr, 'd' },
    636         { "old-ast", no_argument, nullptr, 'O'},
    637         { "new-ast", no_argument, nullptr, 'A'},
    638545        { "print", required_argument, nullptr, 'P' },
    639546        { "prelude-dir", required_argument, nullptr, PreludeDir },
     
    657564        "do not generate prelude prototypes => prelude not printed", // -p
    658565        "only print deterministic output",                  // -d
    659         "Use the old-ast",                                                                      // -O
    660         "Use the new-ast",                                                                      // -A
    661566        "print",                                                                                        // -P
    662567        "<directory> prelude directory for debug/nodebug",      // no flag
     
    767672                        deterministic_output = true;
    768673                        break;
    769                   case 'O':                                     // don't print non-deterministic output
    770                         useNewAST = false;
    771                         break;
    772                   case 'A':                                     // don't print non-deterministic output
    773                         useNewAST = true;
    774                         break;
    775674                  case 'P':                                                                             // print options
    776675                        for ( int i = 0;; i += 1 ) {
     
    889788
    890789static void dump( ast::TranslationUnit && transUnit, ostream & out ) {
    891         std::list< Declaration * > translationUnit = convert( move( transUnit ) );
     790        std::list< Declaration * > translationUnit = convert( std::move( transUnit ) );
    892791        dump( translationUnit, out );
    893792}
Note: See TracChangeset for help on using the changeset viewer.