Changeset de31a1d


Ignore:
Timestamp:
Nov 8, 2021, 10:51:48 AM (3 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
cb921d4
Parents:
817bb3c
Message:

Converted the two LabelGenerator? singletons into a single pure-static class.

Location:
src/ControlStruct
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/FixLabels.cpp

    r817bb3c rde31a1d  
    2828class FixLabelsCore final : public ast::WithGuards {
    2929        LabelToStmt labelTable;
    30         LabelGenerator_new * label_gen;
     30        LabelGenerator * label_gen;
    3131public:
    32         FixLabelsCore( LabelGenerator_new * gen = nullptr ) :
     32        FixLabelsCore( LabelGenerator * gen = nullptr ) :
    3333                labelTable(),
    34                 label_gen( gen ? gen : LabelGenerator_new::getGenerator() )
     34                label_gen( gen ? gen : LabelGenerator::getGenerator() )
    3535        {}
    3636
  • src/ControlStruct/LabelGenerator.cc

    r817bb3c rde31a1d  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Nov  1 12:21:00 2021
    13 // Update Count     : 16
     12// Last Modified On : Mon Nov  8 10:18:00 2021
     13// Update Count     : 17
    1414//
    1515
     
    2828
    2929namespace ControlStruct {
    30         LabelGenerator * LabelGenerator::labelGenerator = 0;
     30
     31int LabelGenerator::current = 0;
     32LabelGenerator * LabelGenerator::labelGenerator = nullptr;
    3133
    3234        LabelGenerator * LabelGenerator::getGenerator() {
     
    4850        }
    4951
    50 LabelGenerator_new * LabelGenerator_new::labelGenerator = nullptr;
    51 
    52 LabelGenerator_new * LabelGenerator_new::getGenerator() {
    53         if ( nullptr == labelGenerator ) {
    54                 labelGenerator = new LabelGenerator_new();
    55         }
    56         return labelGenerator;
    57 }
    58 
    59 ast::Label LabelGenerator_new::newLabel(
     52ast::Label LabelGenerator::newLabel(
    6053                const std::string & suffix, const ast::Stmt * stmt ) {
    6154        assert( stmt );
  • src/ControlStruct/LabelGenerator.h

    r817bb3c rde31a1d  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Nov  1 12:19:00 2021
    13 // Update Count     : 7
     12// Last Modified On : Mon Nov  8 10:16:00 2021
     13// Update Count     : 8
    1414//
    1515
     
    2727
    2828namespace ControlStruct {
    29         class LabelGenerator {
    30           public:
    31                 static LabelGenerator *getGenerator();
    32                 Label newLabel(std::string suffix, Statement * stmt = nullptr);
    33                 void reset() { current = 0; }
    34                 void rewind() { current--; }
    35           protected:
    36                 LabelGenerator(): current(0) {}
    37           private:
    38                 int current;
    39                 static LabelGenerator *labelGenerator;
    40         };
    4129
    42 class LabelGenerator_new {
    43         int current;
    44         static LabelGenerator_new *labelGenerator;
    45 
    46         LabelGenerator_new() : current(0) {}
     30class LabelGenerator {
     31        static int current;
     32        static LabelGenerator *labelGenerator;
     33protected:
     34        LabelGenerator() {}
    4735public:
    48         static LabelGenerator_new *getGenerator();
    49 
    50         ast::Label newLabel( const std::string& suffix, const ast::Stmt * stmt );
    51         void reset() { current = 0; }
    52         void rewind() { --current; }
     36        static LabelGenerator *getGenerator();
     37        static Label newLabel(std::string suffix, Statement * stmt = nullptr);
     38        static ast::Label newLabel( const std::string&, const ast::Stmt * );
     39        static void reset() { current = 0; }
     40        static void rewind() { current--; }
    5341};
    5442
  • src/ControlStruct/MultiLevelExit.cpp

    r817bb3c rde31a1d  
    105105                public ast::WithVisitorRef<MultiLevelExitCore>,
    106106                public ast::WithShortCircuiting, public ast::WithGuards {
    107         MultiLevelExitCore( const LabelToStmt & lt, LabelGenerator_new * lg );
     107        MultiLevelExitCore( const LabelToStmt & lt, LabelGenerator * lg );
    108108
    109109        void previsit( const ast::FunctionDecl * );
     
    131131        std::vector<Entry> enclosing_control_structures;
    132132        ast::Label break_label;
    133         LabelGenerator_new * label_gen;
     133        LabelGenerator * label_gen;
    134134        bool inFinally;
    135135
     
    155155
    156156MultiLevelExitCore::MultiLevelExitCore(
    157                 const LabelToStmt & lt, LabelGenerator_new * lg ) :
     157                const LabelToStmt & lt, LabelGenerator * lg ) :
    158158        target_table( lt ), break_label( CodeLocation(), "" ), label_gen( lg ),
    159159        inFinally( false )
     
    608608        const ast::CompoundStmt * stmt,
    609609                const LabelToStmt & labelTable,
    610                 LabelGenerator_new * labelGen ) {
     610                LabelGenerator * labelGen ) {
    611611        // Must start in the body, so FunctionDecls can be a stopping point.
    612612        ast::Pass<MultiLevelExitCore> visitor( labelTable, labelGen );
  • src/ControlStruct/MultiLevelExit.hpp

    r817bb3c rde31a1d  
    2626namespace ControlStruct {
    2727
    28 class LabelGenerator_new;
     28class LabelGenerator;
    2929using LabelToStmt = std::map<ast::Label, const ast::Stmt *>;
    3030
    3131/// Mutate a function body to handle multi-level exits.
    3232const ast::CompoundStmt * multiLevelExitUpdate(
    33         const ast::CompoundStmt *, const LabelToStmt &, LabelGenerator_new *);
     33        const ast::CompoundStmt *, const LabelToStmt &, LabelGenerator *);
    3434
    3535}
Note: See TracChangeset for help on using the changeset viewer.