Ignore:
Timestamp:
Aug 19, 2016, 12:57:05 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
04cdd9b, 2037f82
Parents:
8b7ee09
Message:

removed more memory leaks from the system

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ParseNode.h

    r8b7ee09 rac71a86  
    103103//##############################################################################
    104104
    105 class ExpressionNode : public ParseNode {
     105class ExpressionNode final : public ParseNode {
    106106  public:
    107107        ExpressionNode( Expression * expr = nullptr ) : expr( expr ) {}
     
    114114        ExpressionNode *set_extension( bool exten ) { extension = exten; return this; }
    115115
    116         virtual void print( std::ostream &os, int indent = 0 ) const {}
    117         virtual void printOneLine( std::ostream &os, int indent = 0 ) const {}
    118 
    119         virtual Expression *build() const { return expr; }
     116        void print( std::ostream &os, int indent = 0 ) const {}
     117        void printOneLine( std::ostream &os, int indent = 0 ) const {}
     118
     119        template<typename T>
     120        bool isExpressionType() const {
     121                return nullptr != dynamic_cast<T>(expr.get());
     122        }
     123
     124        Expression *build() const { return const_cast<ExpressionNode*>(this)->expr.release(); }
    120125  private:
    121126        bool extension = false;
    122         Expression *expr;
     127        std::unique_ptr<Expression> expr;
    123128};
    124129
     
    151156};
    152157
    153 Expression *build_constantInteger( std::string &str );
    154 Expression *build_constantFloat( std::string &str );
    155 Expression *build_constantChar( std::string &str );
    156 ConstantExpr *build_constantStr( std::string &str );
     158Expression *build_constantInteger( const std::string &str );
     159Expression *build_constantFloat( const std::string &str );
     160Expression *build_constantChar( const std::string &str );
     161ConstantExpr *build_constantStr( const std::string &str );
    157162
    158163NameExpr *build_varref( const std::string *name, bool labelp = false );
     
    304309//##############################################################################
    305310
    306 class StatementNode : public ParseNode {
     311class StatementNode final : public ParseNode {
    307312  public:
    308313        StatementNode() { stmt = nullptr; }
     
    311316        virtual ~StatementNode() {}
    312317
    313         virtual StatementNode *clone() const { assert( false ); return nullptr; }
    314         virtual Statement *build() const { return stmt; }
     318        virtual StatementNode *clone() const final { assert( false ); return nullptr; }
     319        Statement *build() const { return const_cast<StatementNode*>(this)->stmt.release(); }
    315320
    316321        virtual StatementNode *add_label( const std::string * name ) {
    317322                stmt->get_labels().emplace_back( *name );
     323                delete name;
    318324                return this;
    319325        }
     
    324330        virtual void printList( std::ostream &os, int indent = 0 ) {}
    325331  private:
    326         Statement *stmt;
     332        std::unique_ptr<Statement> stmt;
    327333}; // StatementNode
    328334
Note: See TracChangeset for help on using the changeset viewer.